Reputation: 9
I'm been programming Java for a long time and recently I've started Python but there's something I can't figure out
import re
test_string = "1989 1989"
matched = re.match("\\d+", test_string)
print(bool(matched))
I'm expecting it to return false, however it returns true. basically I'm just looking for the counterpart of String.matches() in java... I thought maybe you could help me out! thank you in advance
Upvotes: 0
Views: 135
Reputation: 6786
re.match
matches if any prefix of the string matches the pattern. You probably want re.fullmatch
, which checks whether the entire string matches the pattern.
Upvotes: 1