JavaScript extract email from string | regex example code

Use JavaScript to find email address in a string?

Use the match method with a regular expression to extract email from a string in JavaScript.

Simple RegEx to extract email address from string

Note: It will match not match 100% of the email patterns.

Example of JavaScript extract email from string

In the example, we created a function with regex /([a-zA-Z0-9._-][email protected][a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/ to extract email ids (address) from the long text.


JavaScript extract email from string

Here’s the decomposition of the regex /<(.*)>/ :

  • / and / are mandatory to define a regex
  • < and > simply matches the two < and > in your string
  • () parenthesis “capture” what you’re looking for. Here, they get the mail address inside.
  • .* : . means “any character”, and * means “any number of times. Combined, it means “any character any number of times”, and that is inside < and >, which correspond to the place where the mail is.

Q: How to Extract all email addresses from bulk text using JS?

Answer: Here is HTML example code with easy approach:

Do comment if you have any doubts and suggestion with code in this topic.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.