Jul-11-2018, 11:29 AM
Dear Python/Regex Experts,
I have two regex patterns that I use in Python that need a little improvement.
1. #m/d/yy month in Digits e.g. 1/2/98
pattern1 = r'(\d{1}/\d{1}/\d{2})'
I need an extra condition that after those final yy digits, there should be no other digits coming.
If they do, it is covered by a different pattern or not actually a date.
2. #yyyy e.g. 1984
pattern2 = '(\d{4})'
For the second pattern, I need to make sure that the year stands alone and has no more digits before or after.
I would really appreciate any help.
I have two regex patterns that I use in Python that need a little improvement.
1. #m/d/yy month in Digits e.g. 1/2/98
pattern1 = r'(\d{1}/\d{1}/\d{2})'
I need an extra condition that after those final yy digits, there should be no other digits coming.
If they do, it is covered by a different pattern or not actually a date.
2. #yyyy e.g. 1984
pattern2 = '(\d{4})'
For the second pattern, I need to make sure that the year stands alone and has no more digits before or after.
I would really appreciate any help.