Sus*_*ush 4 regex jquery node.js
我是常规表现的新手,我有以下数据,我希望获得唯一的电子邮件ID.如何使用常规表达式
commit 01
emailid: Tests <tests@gmail.com>
Date: Wed Jun 18 12:55:55 2014 +0530
details
commit 02
emailid: user <user@gmail.com>
Date: Wed Jun 18 12:55:55 2014 +0530
location
commit 03
emailid: Tests <tests@gmail.com>
Date: Wed Jun 18 12:55:55 2014 +0530
france24
commit 04
emailid: developer <developer@gmail.com>
Date: Wed Jun 18 12:55:55 2014 +0530
seloger
Run Code Online (Sandbox Code Playgroud)
从这个使用常规experssion我怎么可以retirve tests@gmail.com,user@gmail.com,developer@gmail.com
有了这个正则表达式:
emailid: [^<]*<([^>]*)
Run Code Online (Sandbox Code Playgroud)
emailid: 匹配该字符串文字[^<]*<匹配任何不是a的字符<,然后匹配<([^>]*)捕获所有不属于>第1组的字符.这是您的emailid.在正则表达式演示中,查看右侧窗格中的"组捕获".这就是我们正在寻找的.
获取唯一的电子邮件
对于每个匹配,我们检查emailid是否已经在我们的唯一电子邮件ID数组中.请参阅此JS演示的输出.
var uniqueids = [];
var string = 'blah emailid: Tests <tests@gmail.com> emailid: user <user@gmail.com> emailid: Tests <tests@gmail.com> emailid: developer <developer@gmail.com>'
var regex = /emailid: [^<]*<([^>]*)/g;
var thematch = regex.exec(string);
while (thematch != null) {
// print the emailid, or do whatever you want with it
if(uniqueids.indexOf(thematch[1]) <0) {
uniqueids.push(thematch[1]);
document.write(thematch[1],"<br />");
}
thematch = regex.exec(string);
}
Run Code Online (Sandbox Code Playgroud)