Regex to Take into Account Preceding Word in Python [duplicate]
I have been using the regex below to gather decimal values. The format of the source data has recently changed so I need to edit it to omit certain values.
Now the decimal values I want to gather will always be preceded by the word "price " (with the space).
I am struggling to amend it to work. Can anyone point me in the right direction?
print(re.findall(r'(\d{1,2}\.\d*)', txt_string))
Solution 1:
If the word is always written as "price" (lowercase):
print(re.findall(r'price (\d{1,2}\.\d*)', txt_string)).group(1)
If it can also start with a capital letter:
print(re.findall(r'[Pp]rice (\d{1,2}\.\d*)', txt_string)).group(1)