我是新手,我有以下数据
从这里我想得到唯一的电子邮件ID。如何使用常规expresson

 commit 01
 emailid: Tests <[email protected]>
 Date:   Wed Jun 18 12:55:55 2014 +0530

 details

 commit 02
 emailid: user <[email protected]>
 Date:   Wed Jun 18 12:55:55 2014 +0530

  location
 commit 03
 emailid: Tests <[email protected]>
 Date:   Wed Jun 18 12:55:55 2014 +0530

    france24
 commit 04
 emailid: developer <[email protected]>
 Date:   Wed Jun 18 12:55:55 2014 +0530

    seloger

从这一点出发,使用常规的expersion,我如何才能重新预订[email protected],[email protected],[email protected]

最佳答案

使用此正则表达式:

emailid: [^<]*<([^>]*)

emailid:匹配该字符串文本
[^<]*<匹配任何不是a<的字符,然后匹配<
([^>]*)捕获不属于组1的所有字符。这是你的电子邮箱。
the regex demo中,查看右窗格中的组捕获。这就是我们要找的。
获取唯一的电子邮件ID
对于每一个匹配项,我们检查emailid是否已经在我们的唯一emailid数组中。查看此JS demo的输出。
var uniqueids = [];
var string = 'blah emailid: Tests <[email protected]>  emailid: user <[email protected]> emailid: Tests <[email protected]> emailid: developer <[email protected]>'
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);
}

07-28 11:45