mardi 22 janvier 2019

python date regex expression

I am trying to only add dates to my list.

pattern_six = re.compile(r'\d{1,2}-\d{1,2}-\d{4}')

Unfortunately, this regex expression picks up #2-1 as well, which is not a date.
Question 1: I thought the regex expression would only follow X-X-X pattern, not X-X as well. Why is my assumption wrong?
Question 2: How can I fix my expression to correctly pick up only dates? I tried with this expression but failed.

pattern_six = re.compile(r'[^#](\d{1,2}-\d{1,2}-\d{4})')

Thank you for your help in advance :)

Aucun commentaire:

Enregistrer un commentaire