No match from simple regex in python

hello guys. i am trying to match one or more digit from end of string

import re

print(re.match(r'\d+$', "hello001"))
print(re.match(r'[0-9]+$', "hello001"))

output None from both print statement. I've tried my regex on regex101.com and it seems working probably.

12 points · 2 comments · view on lemmy.world

2 Comments

z500@startrek.website · 13 pts · 2y (1 reply)

From the python docs:

Note that even in MULTILINE mode, re.match() will only match at the beginning of the string and not at the beginning of each line.

If you want to locate a match anywhere in string, use search() instead (see also search() vs. match()).

1_4M_N008@programming.dev · 6 pts · 2y

thanks, i will pay more attention for docs