I have a regex to match email addresses in javascript. Lets see an example:
var email = "aaa@bbb.com (A,B); ccc@ddd.com (C,D); eee@fff.com (E,F);";
var emails = email.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
This will return me all the emails in the var emails.
Now, I have a string:
var initials = "(A,B)";
And I would like to get only the email before the initials value;
If the var initials is “(A,B)”, then I would like to get only the aaa@bbb.com email address.
Thank you a lot for your help!
JavaScript:
Output:
Test this code here.