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

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

ubuntu - Bash Script to Check That Files Are Being Created -