[Tool + Code] Email Address and Phone Number Extractor: Using JavaScript Code to Extract Emails and Phone Numbers with a Regular Expressions
Sometimes, you have to extract emails and/or phone numbers from some text. Here's a tool that does that.
[Tool + Code] Email Address and Phone Number Extractor: Using JavaScript Code to Extract Emails and Phone Numbers with a Regular Expressions
Articles in Web Scraping, Data Analysis | By August R. Garcia
Published | Last Update
Sometimes, you have to extract emails and/or phone numbers from some text. Here's a tool that does that.
1,893 view, 1 RAM, and 0 comments
- [Tool] Email Address and Phone Number Extractor
- Also, JavaScript Code to Extract Emails and Phone Numbers with a REGEX
- What is a RegEx?
- [JavaScript] Extracting Data by RegEx
- How to Extract Email Addresses
- [JavaScript] RegEx to Match Email Addresses
- Matches These Email Addresses
- How to Extract Phone Numbers
- [JavaScript] RegEx to Match Phone Numbers
- Matches These Phone Numbers
- In Conclusion
[Tool] Email Address and Phone Number Extractor
Also, JavaScript Code to Extract Emails and Phone Numbers with a REGEX
Sometimes, you have to extract emails and/or phone numbers from some text. Here's a tool that does that.
Or, scroll down to get the JavaScript code to match/extract emails and/or phone numbers from arbitrary contexts. All code is free to use in any context, including commercial contexts, with no requirement for attribution (i.e., do whatever the fuck you want).
What is a RegEx?
Regular expressions are patterns that can be used to find, replace, extract, and/or otherwise match parts of text. They are similar to something like Ctrl+F, but can be designed to match strings at much higher level of specificity.
While most programming languages, spreadsheet applications, database management systems, and so on will support regular expressions, they are a general standard that is not specific to any particular programming language. Exact implementations can vary between programming languages and standards, although regular expressions are, somehow, basically a consistent standard.
The video above overviews the general concepts behind regular expressions fairly concisely and in a way that is relatively easy to follow with no prior knowledge of RegExes.
[JavaScript] Extracting Data by RegEx
How to Extract Email Addresses
[JavaScript] RegEx to Match Email Addresses
function extract_emails( text ) { var regex = /(?:^|\s|$)([a-zA-Z0-9.\+_-]+@[a-zA-Z0-9._-]+)/gi; var matches = []; var match; while (match = regex.exec(text)) { matches.push(match[1]); } return matches; }
Matches These Email Addresses
The email RegEx has been tested against the list of examples of valid and invalid email addresses listed on Wikipedia.
- simple@example.com
- very.common@example.com
- disposable.style.email.with+symbol@example.com
- other.email-with-hyphen@example.com
- fully-qualified-domain@example.com
- user.name+tag+sorting@example.com
- x@example.com
- example-indeed@strange-example.com
- admin@mailserver1
- example@s.example
" "@example.org"john..doe"@example.org
Does not match these invalid email addresses :
- Abc.example.com
A@b@c@example.com- a"b(c)d,e:f;g<h>i[j\k]l@example.com
- just"not"right@example.com
- this is"not\allowed@example.com
- this\ still\"not\\allowed@example.com
1234567890123456789012345678901234567890123456789012345678901234+x@example.com
How to Extract Phone Numbers
[JavaScript] RegEx to Match Phone Numbers
function extract_phone_numbers( text ) { return text.match(/\+?[0-9]?[- \.]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}/ig); }
Matches These Phone Numbers
This RegEx matches phone numbers using these types of patterns:
- 5555555555
- 555 555 5555
- 555-555-5555
- 555.555.5555
- (555) 555-5555
- 15555555555
- 1 555 555 5555
- 1 555-555-5555
- 1 555.555.5555
- 1 (555) 555-5555
- +15555555555
- +1 555 555 5555
- +1 555-555-5555
- +1 555.555.5555
- +1 (555) 555-5555
In Conclusion
Are there other pieces of data that you commonly need to extract? Post a REGEX in the comments and will duct tape it into the tool above. Or post a suggestion and someone more competent than you might even implement it for you.
Or, if this site is too shitty for you, go to some other website, like RegExLib[rary], which has various RegExes, including for matching emails and phone numbers. Or, alternatively, go to a tool like Regex101 to write and/or test your own RegEx.








Huevos Rancheros (2 years ago) 🐏 ⨉ 1Posted by August R. Garcia 2 years ago
Edit History
• [2019-01-15 14:46 PST] August R. Garcia (2 years ago)• [2019-01-15 14:46 PST] August R. Garcia (2 years ago)
• [2019-01-15 14:46 PST] August R. Garcia (2 years ago)
• [2019-01-15 14:46 PST] August R. Garcia (2 years ago)
• [2019-01-15 14:46 PST] August R. Garcia (2 years ago)
• [2019-01-15 14:46 PST] August R. Garcia (2 years ago)
🕓 Posted at 15 January, 2019 14:46 PM PST
- C U 7 Internet Marketing/SEO Tricks from the Slack Chat
- C U [BASH, cURL] Yellow Pages Scraper: Fully Functional Script with Source Code
- C U [cURL, BASH] How to Crawl and Scrape DuckDuckGo Search Results
- C U The Basics to Web Scraping with cURL and XPath
- C U Extracting Emails from HTML with Google Sheets: Get Contact Information in Bulk for Guest Posts, (lmao) 404 Re...
- C U [Infographic] The Beginner's SQLite Cheat Sheet
- C U Analyzing the Web: Downloading the Majestic Million, Setting up SQLite, Crawling the Web, and Generating Repor...
- C U Downloading Bulk Images: ThisPersonDoesNotExist with Python and urllib2
- C U [Tool + Code] Email Address and Phone Number Extractor: Using JavaScript Code to Extract Emails and Phone Numb...
- C U An introduction to scraping with Python and BeautifulSoup
August Garcia is some guy who used to sell Viagra on the Internet. He made this website to LARP as a sysadmin while posting about garbage like user-agent spoofing, spintax, the only good keyboard, virtual assitants from Pakistan, links with the rel="nofollow" attribute, proxies, sin, the developer console, literally every link building method, and other junk.
Available at arg@256kilobytes.com, via Twitter, or arg.256kilobytes.com. Open to business inquiries based on availability.
Post a New Comment
To leave a comment, login to your account or create an account.
Do you like having a good time?
Register an Account
You can also login to an existing account or reset your password. All use of this site is subject to the terms of service and privacy policy.
Read Quality Articles
Read some quality articles. If you can manage to not get banned for like five minutes, you can even post your own articles.
View Articles →
Argue with People on the Internet
Use your account to explain why people are wrong on the Internet forum.
View Forum →
Vandalize the Wiki
Or don't. I'm not your dad.
View Wiki →
Ask and/or Answer Questions
If someone asks a terrible question, post a LMGTFY link.
View Answers →
Make Some Money
Hire freelancers and/or advertise your goods and/or services. Hire people directly. We're not a middleman or your dad. Manage your own business transactions.