Skip to content
Site Stats
總訪問量–次
訪客數–人次

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")