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
Post a Comment