Assume I have the following string:
string = "** Hunger is the physical sensation of desiring food.
<br> Your Hunger Level: Very Hungery<br> Food You Crave: Tomato<br/><br/>"
I want to be able to extract out “Your Hunger” and “Tomato”. Assume that regardless of what special characters are inserted, I know for a fact that “Your Hunger Level:” and “Food You Crave” will always be constant.
"Your Hunger Level:" could be: "Very Hungry", "Hungry", "Not So Hungry"
"Food You Crave:" could be: "Tomato", "Rice and Beans", "Corn Soup"
How do I use a regular expression to match this? I tried the following, but am not getting any luck…
m = re.match('(.*)([ \t]+)?Your Hunger Level:([ \t]+)?(?P<hungerlevel>.*)(.*)Food You Crave:([ \t]+)?(?P<foodcraving>.*).*', string)
NOTE: The string appears to have a lot of escape characters indicated below:
string = "** Hunger is the physical sensation of desiring food. <br>\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tYour Hunger Level:
Very Hungry \n\t\t\t\t\t\t\t\t<br>\n\t\t\t\t\t\t\t\tFood You Crave: Tomato \n\t\t\t\t\t\t</br>"
I’d go for:
Or, you could make it a
dict: