Advertisement
GeorgiLukanov87

task-1

Jan 22nd, 2024
977
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import re
  2.  
  3. text = """
  4. Hi,
  5. my name is Jane and my phone number is 555-123-4567.
  6. My email address is jane_doe@example.com.
  7. 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.
  8. 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.
  9. Thank you!
  10. """
  11.  
  12. # Define a regex pattern to match dates in various formats
  13. date_pattern = re.compile(r'\b(?:\d{4}-\d{2}-\d{2}|\d{4}/\d{2}/\d{2}|[a-zA-Z]+\s\d{1,2}(?:st|nd|rd|th)?,\s\d{4})\b')
  14.  
  15. # Find all matches in the text
  16. matches = date_pattern.findall(text)
  17.  
  18. # Print the extracted dates
  19. print("Extracted Dates:")
  20. for match in matches:
  21.     print(match)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement