1 month ago

Issue grabbing all emails from DOM string with match and regex

Posted 1 month ago by Gabotronix

Hi everybody, I'm trying to extract all emails from a DOM html string using regex and javascript match but I'm getting null, is it because of my regex or the string I'm using to test it?

var bodyHTML = '<header><div><a href="mailto:[email protected]"></a></div></header><a href="mailto:[email protected]"></a>';

        var emailRegex = new RegExp("/([\s]*)([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*([ ]+|)@([ ]+|)([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,}))([\s]*)/i", "g");
        var results = bodyHTML.match(emailRegex); 

Thanks in advance!

Please sign in or create an account to participate in this conversation.