I need to find "7.1/10" in "7.1/10&nb" with the following regex:
\d{1}\.?\d{0,2}\/10
But the following code does not match anything:
rating= "7.1/10&nb"
p = re.compile(re.escape("\d{1}\.?\d{0,2}\/10"))
m = p.match(rating)
if m:
print("rating: {}".format(m.group()))
else:
print("no match found in {}".format(rating))
What's the problem with my code?
rinstead ofre.escapep = re.compile(r"\d{1}\.?\d{0,2}\/10")p = re.compile(re.escape("\d{1}\.?\d{0,2}\/10"))top = re.compile(r"\d{1}\.?\d{0,2}\/10")it will work.match..becausematchmatches only in starting of string..