Regex for email matching

前端 未结 5 1114
忘掉有多难
忘掉有多难 2020-12-11 08:54

I am using this regex to match email addresses in a string.

Everything works fine here: http://regexr.com?31e5a with this regex:

([\\w-\\.]+)@((?:[\         


        
5条回答
  •  一整个雨季
    2020-12-11 09:29

    You pattern is close, you just need to use the global flag and not capture the inner parts of each email acount. I hope it helps.

    var re = /(?:[\w-\.]+)@(?:(?:[\w]+\.)+)(?:[a-zA-Z]{2,4})/g;
    var emailsString = 'aaaaaaa@bbbb.com xxxxxxx cccccc@ffffdd.com';
    var emails = emailsString.match(re); // ["aaaaaaa@bbbb.com", "cccccc@ffffdd.com"]
    

提交回复
热议问题