Skip to content

Instantly share code, notes, and snippets.

@jgwill
Last active December 9, 2018 23:40
Show Gist options
  • Save jgwill/c56948280881b060c9dfe30600f773b9 to your computer and use it in GitHub Desktop.
Save jgwill/c56948280881b060c9dfe30600f773b9 to your computer and use it in GitHub Desktop.
@stcaction How to extract email in string using regular expression
//@stcaction How to extract email in string using regular expression
var re = /(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/g;
var text = "my email is my@mydomain.com";
function extractEmails(text) {
return text.match(re);
// return text.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
}
console.log(text.match(re));
@jgwill
Copy link
Author

jgwill commented Dec 9, 2018

Great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment