在gmail中识别“原始消息”前缀有什么好的正则表达式?

时间:2012-03-20 13:10:39

标签: python regex roundup

示例签名可能是:

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

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

我要求这样做的原因是因为roundup在通过gmail回复问题时没有正确删除这些内容。我认为origmsg_re是我需要与keep_quoted_text = no一起设置的config.ini变量来修复此问题。

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

修改:现在我正在使用origmsg_re = ^On[^<]+<.+@.+>[ \n]wrote:[\n],它可以与一些破坏太长行的gmail客户端一起使用。

1 个答案:

答案 0 :(得分: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