次の正規表現は、かなり安全な方法で gmail のプレフィックスに一致します。3 つのコンマとリッター テキスト On ... が書かれていることを確認します。
On([^,]+,){3}.*?wrote:
正規表現が大文字と小文字を区別しない方法で一致する必要がある場合は、修飾子を追加することを忘れないでください。
if re.search("On([^,]+,){3}.*?wrote:", subject, re.IGNORECASE):
# Successful match
else:
# Match attempt failed
敬具、バックリー
Match the characters “On” literally «On»
Match the regular expression below and capture its match into backreference number 1 «([^,]+,){3}»
Exactly 3 times «{3}»
Note: You repeated the capturing group itself. The group will capture only the last iteration. Put a capturing group around the repeated group to capture all iterations. «{3}»
Match any character that is NOT a “,” «[^,]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the character “,” literally «,»
Match any single character that is not a line break character «.*?»
Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Match the characters “wrote:” literally «wrote:»
Created with RegexBuddy