Last active
December 9, 2018 23:40
-
-
Save jgwill/c56948280881b060c9dfe30600f773b9 to your computer and use it in GitHub Desktop.
@stcaction How to extract email in string using regular expression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@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)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great