I have a value (a) in my textbox. I want to get the email ids only from the given string using Javascript (I don't want to use any JS Frameworks).
我的文本框中有一个值(a)。我想只使用Javascript从给定的字符串中获取电子邮件ID(我不想使用任何JS框架)。
(a) xxx@gmail.com (Blig fun), yyy@gmail.info (LOl)
I need the output like
xxx@gmail.com
yyy@gmail.info
1 个解决方案
#1
3
Try -
试试 -
var tbstring = '(a) xxx@gmail.com (Blig fun), yyy@gmail.info (LOl)';
result = tbstring.match(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/ig);
alert(result.join('\n'));
Demo - http://jsfiddle.net/ipr101/MM7Aa/
演示 - http://jsfiddle.net/ipr101/MM7Aa/
Email RegEx is taken from the RegEx Buddy library and comes with the following provisos -
电子邮件RegEx取自RegEx Buddy图书馆,附带以下附带条件 -
Does not match email addresses using an IP address instead of a domain name.
与使用IP地址而不是域名的电子邮件地址不匹配。
Does not match email addresses on new-fangled top-level domains with more than 4 letters such as .museum. Including these increases the risk of false positives when applying the regex to random documents.
与超过4个字母的新奇*域名上的电子邮件地址不匹配,例如.museum。在将正则表达式应用于随机文档时,包括这些会增加误报的风险。
#1
3
Try -
试试 -
var tbstring = '(a) xxx@gmail.com (Blig fun), yyy@gmail.info (LOl)';
result = tbstring.match(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/ig);
alert(result.join('\n'));
Demo - http://jsfiddle.net/ipr101/MM7Aa/
演示 - http://jsfiddle.net/ipr101/MM7Aa/
Email RegEx is taken from the RegEx Buddy library and comes with the following provisos -
电子邮件RegEx取自RegEx Buddy图书馆,附带以下附带条件 -
Does not match email addresses using an IP address instead of a domain name.
与使用IP地址而不是域名的电子邮件地址不匹配。
Does not match email addresses on new-fangled top-level domains with more than 4 letters such as .museum. Including these increases the risk of false positives when applying the regex to random documents.
与超过4个字母的新奇*域名上的电子邮件地址不匹配,例如.museum。在将正则表达式应用于随机文档时,包括这些会增加误报的风险。