希望仅解析以下电子邮件线程的最新回复。你好尼基尔波普拉,↵↵只是简单介绍一下,我正在建设一个备用的电子借贷↵平台..
我为涵盖各种用例而编写的通用正则表达式/[\s]*([\s\S]*.)[\s]*\n\n[\s]*On [\s\S]*.<[\s\S]*.> wrote/不适用于↵字符。
有人能帮我用javascript编写一个很好的正则表达式来解析这个表达式吗?
你好,尼基尔,简单介绍一下,我正在建设一个备用的电子借贷平台。2016年1月10日下午1点16分,Deepak Modak↵wrote:↵↵> Deepak Modak已经发送了一份message↵>↵>,我正试图制作一款金融产品,需要您的反馈和insights.↵>↵>请求的TimeSlots:↵>
发布于 2016-02-18 15:28:46
为了给出一个简短的答案,这里是一个单一的正则表达式,应该对您工作,没有任何替代。U21b5表示"↵“,并使之成为可能。如果以后想去掉箭头,只需使用/\u21b5/模式进行单独搜索,并使用空格替换,就像我在前面的答案中所做的那样。
/((.|\u21b5)+?)(?:On\s+[A-Z]{3},\s+[A-Z]{3}\s+\d{1,2},\s+\d{4}\s+at\s+\d|$)/i补充资料:
在最后一次编辑之后,我将尝试不进行此操作,但下面是我认为是对最后一个模式的重大改进。下面的模式也可以独立存在(不需要替换),但是改进(我相信)是没有捕获组。返回的匹配应该准确地显示正在寻找的内容;需要提取子匹配,如最后一个示例所示。这是通过使用正前瞻来完成的。请告诉我是否有更好的方式来传达这一点(例如在评论中)。
/(?:(?:.|\u21b5)+?)(?=(?:On\s+[A-Z]{3},\s+[A-Z]{3}\s+\d{1,2},\s+\d{4}\s+at\s+\d|$))/i发布于 2016-02-17 07:28:20
没有一个干净的RegEx,但我能够让它工作。我分两个步骤这样做,第一步是删除Unicode字符(我想您无论如何都不想在结果中看到这些箭头)。也许只有RegEx才是您想要的,但我提供了所有的代码,希望能够更清楚地说明我所做的事情。我注意到,上面的字符串中的第一个日期在字符串中的第二个日期没有逗号。我认为这正是电子邮件将继续进入的方式,但如果不是,您可以相应地调整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+[A-Z]{3},\s+[A-Z]{3}\s+\d{1,2},\s+\d{4}\s+at\s+\d|$)/i;
match = patt.exec(myString);
console.log("The submatch: " + match[1]);
</script>https://stackoverflow.com/questions/34706574
复制相似问题