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
#3
{1} is an absolutely redundant modifier - \d and \d{1} are equivalent, so why would you want to add extra symbols? It is just wasteful.

{,1} is another issue - but again, ? does the same, only in one symbol instead of 4.

For 2 digits, e.g. \d\d is shorter than \d{2}, so I will still go for the former (but that is a matter of taste).

RE is complex enough without adding redundancies
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
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,234 Jan-04-2023, 09:19 PM
Last Post: tester_V
  [SOLVED] Alternative to regex to extract date from whole timestamp? Winfried 6 1,853 Nov-16-2022, 01:49 PM
Last Post: carecavoador
  regex pattern to extract relevant sentences Bubly 2 1,878 Jul-06-2021, 04:17 PM
Last Post: Bubly
  Regex to extract IPs between () not working mrapple2020 5 3,449 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