Sujet : Re: Code improvement question
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.pythonDate : 17. Nov 2023, 19:20:14
Autres entêtes
Organisation : Stefan Ram
Message-ID : <Or-20231117191916@ram.dialup.fu-berlin.de>
References : 1 2 3 4 5 6 7 8 9 10
Thomas Passin <
list1@tompassin.net> writes:
re.findall(r'\b[0-9]{2,7}-[0-9]{2}-[0-9]{2}\b', txt)
...
I know, and I just wanted to make it explicit for people who didn't know
much about Python regexes.
Or,
def repeat_preceding( min=None, max=None, count=None ):
return '{' + str( count )+ '}' if count else \
'{' + str( min )+ ',' + str( max )+ '}'
digit = '[0-9]'
word_boundary = r'\b'
hyphen = '-'
my_regexp = word_boundary + \
digit + repeat_preceding( min=2, max=7 ) + hyphen + \
digit + repeat_preceding( count=2 ) + hyphen + \
digit + repeat_preceding( count=2 ) + word_boundary
.