Question about metacharacter '*'

Rick Johnson rantingrickjohnson at gmail.com
Sun Jul 6 18:32:11 CEST 2014


[CONTINUED FROM LAST REPLY...]

Likewise if your intent is to filter out any match strings
which contain non-digits, then define the start and stop
points of the pattern:

# Match only if all are digits
>>> re.match(r'\d\d*$', '111aaa222') # fails

# Match only if all are digits and,
# allow leading white-space
>>> re.match(r'\s*\d\d*$', '   111')
<_sre.SRE_Match object at 0x026D8410>
# But not trailing space!
>>> re.match(r'\s*\d\d*$', '   111 ') # fails



More information about the Python-list mailing list