gpt4 book ai didi

javascript - 使用 javascript 从给定字符串获取电子邮件 ID

转载 作者:行者123 更新时间:2023-11-28 21:16:13 24 4
gpt4 key购买 nike

我的文本框中有一个值 (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

最佳答案

尝试-

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'));

演示 - http://jsfiddle.net/ipr101/MM7Aa/

电子邮件正则表达式取自 RegEx Buddy 库,并附带以下条款 -

Does not match email addresses using an IP address instead of a domain name.

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.

关于javascript - 使用 javascript 从给定字符串获取电子邮件 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7515283/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com