从字符串中获取电子邮件

Get an email from a string

本文关键字:电子邮件 获取 字符串      更新时间:2023-09-26

这里的新手

这是我的问题

假设我的字符串是

var string = "this is a string that contains many different words
domain@gmail.com an I want just the email";

我想要的是一个正则表达式或其他不同的东西,只得到这个domain@gmail.com

我试过很多东西,但没有一个能起作用

这是我最后一次尝试

var myRegexp = /@(.*)/;
var match = myRegexp.exec(string);
if(match)
  console.log(match[1]);

这总是返回null或未定义的

有人能帮我解决吗

编辑

我想要搜索@之前和之后的所有内容并在空白上停止的东西

感谢

emails = str.match(/('S[^'s@]*@'S+)/gi)