Advertisement
bai_onzi

JavaScript script that extracts all dates from the text

Feb 4th, 2024
1,319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const text = `Hi,
  2. my name is Jane and my phone number is 555-123-4567.
  3. My email address is jane_doe@example.com.
  4. I live on 123 Main St. Apt. #456, and I was born on January 11th, 1990. I have an appointment on 2023-05-15 at 2:30pm at 789 Oak Ln. #3 and backup on 2023/05/21.
  5. Please give me a call or send me an email to confirm. In case the dates are unavailable, please set up a meeting sometime in June. I would love June 19h.
  6. Thank you!`;
  7.  
  8. const dates =
  9.   /\b\d{4}[-/]\d{2}[-/]\d{2}\b|\b(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}(?:st|nd|rd|th)?,\s\d{4}\b|\b(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}(?:st|nd|rd|th)?\b|\b(?:January|February|March|April|May|June|July|August|September|October|November|December)\s\d{1,2}(?:st|nd|rd|th)?,\s\d{4}\b/g;
  10.  
  11. const extractDates = text.match(dates);
  12.  
  13. console.log("Extracted Dates:");
  14. extractDates.forEach((date) => {
  15.   console.log(date);
  16. });
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement