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

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -