Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. def find_date_type(string_date):
  2.   import re
  3.   group1 = re.findall("[0-9][0-9] - [a-zA-Z]",string_date)
  4.   group11 = re.findall("[0-9][0-9]-[a-zA-Z]",string_date)
  5.  
  6.   group2 = re.findall("[0-9][0-9]/[0-9][0-9]",string_date)
  7.   group22 = re.findall("[0-9][0-9] / [0-9][0-9]",string_date)
  8.  
  9.   group3 = re.findall("[a-zA-Z] - [a-zA-Z]", string_date)
  10.   group33 = re.findall("[a-zA-Z]-[a-zA-Z]", string_date)
  11.  
  12.   if group1 or group11:
  13.     group_type = 1
  14.   elif group2 or group22:
  15.     group_type = 2
  16.   elif group3 or group33:
  17.     group_type=3
  18.   else:
  19.     group_type=0
  20.   return group_type
  21.  
  22. #group1 = Jan 16-Febr 19
  23. #group11 = Jan 16 - Febr 19  (the dash has spaces)
  24.  
  25. #group2 = 2011/2012
  26. #group22 = 2011 / 2012
  27.  
  28. #group3 = June - July 2020
  29. #group33 = June-July 2020 (#no space in the dash)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement