I have the following text chunk:
string = """
apples: 20
oranges: 30
ripe: yes
farmers:
elmer fudd
lives in tv
farmer ted
lives close
farmer bill
lives far
selling: yes
veggies:
carrots
potatoes
"""
I am trying to find a good regex that will allow me to parse out the key values. I can grab the single line key values with something like:
'(.+?):\s(.+?)\n'
However, the problem comes when I hit farmers, or veggies.
Using the re flags, I need to do something like:
re.findall( '(.+?):\s(.+?)\n', string, re.S),
However, I am having a heck of a time grabbing all of the values associated with farmers.
There is a newline after each value, and a tab, or series of tabs before the values when they are multiline.
and goal is to have something like:
{ 'apples': 20, 'farmers': ['elmer fudd', 'farmer ted'] }
etc.
Thank you in advance for your help.