【问题标题】:What would be a good regexp for identifying the "original message" prefix in gmail?什么是识别gmail中“原始消息”前缀的好正则表达式?
【发布时间】:2012-03-20 13:10:38
【问题描述】:

一个示例签名可能是:

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 = ^[&gt;|\s]*-----\s?Original Message\s?-----$

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

【问题讨论】:

    标签: python regex roundup


    【解决方案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
    

    【讨论】:

    • 谢谢,不过我最终还是用了这个:origmsg_re = ^On.+&lt;.+@.+&gt; wrote:$
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-26
    相关资源
    最近更新 更多