python - match a regex in a formatted alphanumeric string -



python - match a regex in a formatted alphanumeric string -

why

re.match(r"^[0-9]+minutes?$", "10 minute")

is not matching ?

i used :

re.match(r"\d+minutes?$", "10 minute")

you forget add together pattern (\s) match in-between space.

>>> re.match(r"\d+\sminutes?$", "10 minute") <_sre.sre_match object; span=(0, 9), match='10 minute'>

since re.match tries match input string begining, don't need set starting anchor ^.

python regex

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -