Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

javascript - 如何在Javascript中通过正则表达式获取多个电子邮件地址[重复](How to get multiple email addresses via regex in Javascript [duplicate])

This is the regex pattern I'm using which works fine but only returns one match in the resulting array.

(这是我正在使用的正则表达式模式,它工作正常,但仅在结果数组中返回一个匹配项。)

([a-zA-Z0-9+._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)

snippet:

(片段:)

var re = '([a-zA-Z0-9+._-]+@[a-zA-Z0-9._-]+.[a-zA-Z0-9_-]+)';
var s = {a:12, b: '[email protected]', c:'[email protected]'};
var x = JSON.stringify(s);
var z = x.match(re);
console.log(z);
> Array ["[email protected]", "[email protected]"]

Expected: Array ["[email protected]", "[email protected]"] I would like an array with just the matched email addresses.

(预期:数组[“ [email protected]”,“ [email protected]”]我想要一个仅包含匹配电子邮件地址的数组。)

I tried a global match by adding a trailing /g but the result I get is null.

(我通过添加尾随/ g尝试进行全局匹配,但得到的结果为null。)

/([a-zA-Z0-9+._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/g

  ask by L P translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...