Python:
Write a RegEx that can check if a string is a specific date format; For example dateString = '11-09-2016'
Python code:
import re
#defining regex for checking date
regex='\d[0-2]-[0-1]\d-\d\d\d\d'
#test date
date="11-09-2016"
#checking if the date match the format
date_match=re.search(regex,date)
#checking if the date is in the correct format
if date_match:
#printing date is in the correct format
print("date is in the correct format")
else:
#printing date is not in the correct format
print("date is not in the correct format")
Screenshot:
Output:
Get Answers For Free
Most questions answered within 1 hours.