fork download
  1. import calendar, re
  2.  
  3. months_abr = "|".join(calendar.month_abbr[1:]).lower()
  4. months_exp = "|".join(calendar.month_name[1:]).lower()
  5.  
  6. pattern = fr"""
  7. (?<!\d)
  8. (
  9. (?:\d?\d[./])?\d\d(?:\d\d)?
  10. |
  11. (?:{months_abr}|{months_exp}) [\s./-]? \d\d(?:\d\d)?
  12. )
  13. \s*(?:-|to)\s*
  14. (
  15. (?:\d?\d[./])?\d\d(?:\d\d)?
  16. |
  17. (?:{months_abr}|{months_exp}) [\s./-]?\d\d(?:\d\d)?
  18. |
  19. current|present|(?:un)?till\s?-?(?:date|now|date)|to\s-?present
  20. )
  21. """
  22. text = r"Google, Inc 09/19 - 09/20 CA, USA\n3/2006-6/2007\nsss 2017 - present (or) 2015 - 2018 sss"
  23. find_all = re.findall(
  24. pattern, text, flags=re.VERBOSE | re.IGNORECASE
  25. )
  26. print(find_all)
Success #stdin #stdout 0.02s 10052KB
stdin
Standard input is empty
stdout
[('09/19', '09/20'), ('3/2006', '6/2007'), ('2017', 'present'), ('2015', '2018')]