想要一个额定的expression式来parsing一个↵字符的电子邮件答复

想要parsing下面的电子邮件线程的最新答复。 也就是说, 你好Nikhil Bopora,我只是在简要介绍一下,我正在build立一个替代的电子借贷平台。

我写的一般正则expression式覆盖各种用例/[\s]*([\s\S]*.)[\s]*\n\n[\s]*On [\s\S]*.<[\s\S]*.> wrote/不是在字符上工作。

有人可以帮我写一个良好的正则expression式在JavaScript来parsing这个。

Nikhil,你好,简单的说,我正在build立一个备用的电子借贷平台。在下午1点16分,Sun,Deepak Modak写了: Deepak Modak已经发出了一个消息 > I>我正在尝试构build一个金融产品,需要您的反馈和洞察力。>请求的时间段:> —————– ———>> Mon Jan 11 2016,10: 00 PM↵>↵>

试图给出一个简短的答案,这里是一个单一的正则expression式,应该为你工作,没有任何替代。 代表“↵”并使之成为可能。 如果你想稍后摆脱箭头,只要做一个单独的search与/ /模式,并replace一个空格,就像我在以前的答案中所做的。

 /((.|\u21b5)+?)(?:On\s+[AZ]{3},\s+[AZ]{3}\s+\d{1,2},\s+\d{4}\s+at\s+\d|$)/i 

补充信息:

在最后一次编辑之后,我会尽量保留这一点,但下面是我认为对最后一个模式的重大改进。 下面的模式也可以独立(不需要replace),但是改进(我相信)是没有捕获组。 返回的比赛应该显示正在寻找什么; 就像在最后一个例子中一样,需要拉出子匹配。 这是通过使用积极的前瞻来完成的。 请让我知道是否有更好的方式来expression这一点(例如在评论中)。

 /(?:(?:.|\u21b5)+?)(?=(?:On\s+[AZ]{3},\s+[AZ]{3}\s+\d{1,2},\s+\d{4}\s+at\s+\d|$))/i 

没有一个干净的RegEx,但我能够得到这个工作。 我分两步做了这个,首先删除了Unicode字符(我猜你不希望在结果中看到这些箭头)。 也许只有RegEx是你想要的,但是我提供了所有的代码,希望能够更清楚地说明我所做的。 我注意到的一件事是,上面的string中的第一个date在string中的第二个date没有的date有逗号。 我假设这是电子邮件将继续进来,但如果没有,您可以相应地调整RegEx。 我希望这有帮助。

  <script> "use strict"; var patt = /()/; var myString = ""; var match=[]; myString = "Hello Nikhil,↵↵Just to give a brief, I am in process of building an alternate e-lending↵platform.↵↵↵On Sun, Jan 10, 2016 at 1:16 PM, Deepak Modak ↵wrote:↵↵> Deepak Modak has sent a message↵>↵> I am trying to build a financial product, need your feedback & insights.↵>↵> Requested TimeSlots:↵> --------------------------↵> Mon Jan 11 2016, 10:00 PM↵>↵>↵>"; //for the replace regex, using the required 4 hexadecimal digits "21b5" that represent the unicode character "downwards arrow with corner leftwards" patt = /\u21b5/g; //replacing arrow with empty space myString = myString.replace(patt," "); //resetting the pattern. I added a pipe (or) to account for the possibility that the email is not a reply. Looking for "On Sun, Jan 10, 2016 at 1" or similar pattern to represent start of end of captured group of interest. patt = /(.+?)(?:On\s+[AZ]{3},\s+[AZ]{3}\s+\d{1,2},\s+\d{4}\s+at\s+\d|$)/i; match = patt.exec(myString); console.log("The submatch: " + match[1]); </script>