I want to search through a string and find units in fahrenheit and convert them into celcius.
To do this, my approach is to user regex to find units in fahrenheit in a given string, and if I find any, get the number and convert it into celcius.
This is the regex I have come up with:
regexp = re.compile("\d+(.*?)(\bfahrenheit\b|\bf\b)", re.IGNORECASE)
And here is the regex in action.
On the Pythex site it seems to work OK, however, in my interpreter the same regex does not match anything.
Any suggestions?
You need to use a raw string, or \b will mean "backspace" instead of "word boundary":
regexp = re.compile(r"\d+(.*?)(\bfahrenheit\b|\bf\b)", re.IGNORECASE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With