2

示例签名可能是:

On Tue, Mar 20, 2012 at 2:38 PM, Johnny Walker <johnny.talker@gmail.com> wrote:

然后按照引用的答复。我确实有一种离散的感觉,这是特定于语言环境的,但这让我成为一个可悲的程序员。

我要求这样做的原因是因为在通过gmail回复问题时,综述没有正确剥离这些内容。我认为origmsg_re是我需要设置的 config.ini 变量keep_quoted_text = no来解决这个问题。

现在是默认的origmsg_re = ^[>|\s]*-----\s?Original Message\s?-----$

编辑:现在我正在使用origmsg_re = ^On[^<]+<.+@.+>[ \n]wrote:[\n]它与一些断行太长的 gmail 客户端一起使用。

4

1 回答 1

1

以下正则表达式将以非常安全的方式匹配 gmails 前缀。它确保有 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
于 2012-03-20T13:55:55.900 回答