You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the first of the advanced microparsons practice problems for regex. \d{2}/\d{2}/(\d{2}|\d{4}) should be \d{2}/\d{2}/(\d{4}|\d{2})
If the longer \d{4} is not first then it will always match with the \d{2} and will return the first two digits of the year for example 20 of 2025 if the full four digit year is provided.
In [1]: import re
In [2]: re.match(r'\d{2}/\d{2}/(\d{2}|\d{4})', '12/22/2024')
Out[2]: <re.Match object; span=(0, 8), match='12/22/20'>
In [3]: re.match(r'\d{2}/\d{2}/(\d{2}|\d{4})', '12/22/24')
Out[3]: <re.Match object; span=(0, 8), match='12/22/24'>
In [4]: re.match(r'\d{2}/\d{2}/(\d{4}|\d{2})', '12/22/24')
Out[4]: <re.Match object; span=(0, 8), match='12/22/24'>
In [5]: re.match(r'\d{2}/\d{2}/(\d{4}|\d{2})', '12/22/2024')
Out[5]: <re.Match object; span=(0, 10), match='12/22/2024'>
In [6]: re.match(r'\d{2}/\d{2}/(\d{2}|\d{4})', '12/22/2024').groups()
Out[6]: ('20',)
The text was updated successfully, but these errors were encountered:
A user reported this on the discord.
This is the first of the advanced microparsons practice problems for regex.
\d{2}/\d{2}/(\d{2}|\d{4})
should be\d{2}/\d{2}/(\d{4}|\d{2})
If the longer
\d{4}
is not first then it will always match with the\d{2}
and will return the first two digits of the year for example 20 of 2025 if the full four digit year is provided.The text was updated successfully, but these errors were encountered: