Skip to content
本站總訪問量
本站訪客數 人次

Regex 正規表達式 - Python

範例1

python
import re

with open("in.txt", "r") as f:
    lines = f.readlines()
    pattern = r'question:\s*"([^"]+)"'
    for line in lines:
        matchs = re.findall(pattern, line)
        with open("out.txt", "w") as out:
            for match in matchs:
                out.write(match + "\n")

Contributors

The avatar of contributor named as lucashsu95 lucashsu95

Changelog