I'm trying to extract a price from a title of a post and compare it with another price. I found this regular expression pattern: \d{1,3}(?:[.,]\d{3})*(?:[.,]\d{2})
that fits my needs perfectly.
I tested it out on https://regexr.com/ and it returns a correct match. however when I try to do that in python 3 I get no matches. here's what the code looks like:
def isPriceBetter(CurrentPrice, title):
r = re.compile(r'\d{1,3}(?:[.,]\d{3})*(?:[.,]\d{2})')
newPrice = r.match(title)
if newPrice == None:
return False
newPrice = float(newPrice)
if newPrice > CurrentPrice:
return False
return True
newPrice
variable is always None
even though I tested the exact same string that the code is testing on https://regexr.com/ and it returns a match. At first I thought my pattern string was probably being escaped incorrectly which is why I put 'r' in front of the quotes. I've also tried adding more '\' characters but that didn't work either.