HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
1. Feel Free to ask and submit anything on and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.

javascript-regex: How to extract email id phone number date time from a large text?

I need to extract only the email ids, phone numbers, dates, time from a large text. Please give me some sample code to extract it.

javascript x 33
regex x 7
Posted On : 2017-10-26 22:46:21.0
profile Aryan Gupta - Aryan Gupta


I will suggest you to use regular expression to extract the mentioned information. Please refer below regex to extract the phone, email, dates and time.

Phone: /[\+]?\d{10}|\(\d{3}\)\s?-\d{6}/
Email: /([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi
Date: /(\d{4}([.\-/ ])\d{2}\2\d{2}|\d{2}([.\-/ ])\d{2}\3\d{4})/
Time: ([\d]{1,2}:[\d]{1,2}|[\d]{1,2}:[\d]{1,2} [aApP][mM])

Above regular expression are valid for some specified formats and you may need to change it as per your requirement. This is just as reference. Further to get the values you can use these regular expression like below:

var rawemail = document.extractor.rawdata.value.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);

rawemail is an array of email Strings. Similarly you can use other regex too. Above regular expressions are able to extract all kind of emails and time in format [20:03 ,3:39 pm, 4:29 PM] and Date in format [31.07.2018, 07.31.2018, 2018.07.31 the same format but divided by spaces or / or -] and Phone numbers in format [xxxxxxxxxx, (xxx)-xxxxxx]

Here is one example and demo to extract emails from large text. Please check it out this too.

Extracting email ids from a large text in javascript- Click Here

Demo for extracting email ids from a large text using javascript- Click Here

Posted On : 2017-10-27 16:30:35
Satisfied : 1 Yes  0 No
profile Rishi Kumar - Rishi Kumar
Reply This Thread

Post Answer
Please Login First to Post Answer: Login login with facebook -