Regular expression to get email identifiers from data

Being new to regular exclusions, I have the following data from this I want to get a unique email id. How to use regex

 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

From this, using regular shutdown, how can I edit tests@gmail.com,user@gmail.com,developer@gmail.com

+4
source share
1 answer

With this regex:

emailid: [^<]*<([^>]*)
  • emailid: matches this string literal
  • [^<]*<matches any characters that are not <, and then matches<
  • ([^>]*)captures all characters that are not >for group 1. This is your email address.

- regex . , .

, . JS demo.

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);
}
+5

Source: https://habr.com/ru/post/1545159/


All Articles