0

A Newbie here

This is my problem

Let say my string is

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

what I want is a regex or something different that gets just this domain@gmail.com

I've tried many things but none has worked

this is the last one I've tried

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

this always returns null or undefined

can anyone help me out

EDIT

I want something that search for everything before and after @ and stops on blank space

thanks

Hyra10
  • 460
  • 2
  • 6
  • 18

1 Answers1

1
emails = str.match(/(\S[^\s@]*@\S+)/gi)
jusopi
  • 6,791
  • 2
  • 33
  • 44