Python Forum
regex to extract only yy or yyyy
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
regex to extract only yy or yyyy
#1
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.
Reply


Messages In This Thread
regex to extract only yy or yyyy - by metalray - Jul-11-2018, 11:29 AM
RE: regex to extract only yy or yyyy - by snippsat - Jul-11-2018, 12:40 PM
RE: regex to extract only yy or yyyy - by volcano63 - Jul-11-2018, 07:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need to sum up HHMMS AM/PM DD/MM/YYYY and a HH:MM:SS. tester_V 3 1,251 Jan-04-2023, 09:19 PM
Last Post: tester_V
  [SOLVED] Alternative to regex to extract date from whole timestamp? Winfried 6 1,886 Nov-16-2022, 01:49 PM
Last Post: carecavoador
  regex pattern to extract relevant sentences Bubly 2 1,903 Jul-06-2021, 04:17 PM
Last Post: Bubly
  Regex to extract IPs between () not working mrapple2020 5 3,470 Apr-12-2019, 08:03 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020