1

I have the following text in a larger text file:

CHANNEL = ['AngR', 'Time', 'Disp', 'Velo', &
    'Acce', 'Load', 'Forc', 'BLod']
UNIT = ['deg', 's', 'ft', 'ft/s', 'ft/s^2', &
    'N', 'lbf', 'N']

Im looking to parse the data such that i have independent lists for Channel and UNIT

I can get Channel and UNIT with the following script:

matches1 = re.findall(r"(\w+)\s*\=", filetext)  #CHANNEL, UNIT

I am however having difficulty grabbing the data between brackets into lists:

my_regex2 = re.escape(matches1[0])+r"\s*\=\s*\[['(\w+)',*\s*\&*\n]+\]"
matches2 = re.findall(my_regex2, filetext)

this result gives me the entire string for some reason.

This more abbreviated form gives me just the first item in the csv (i.e. 'AngR' for CHANNEL)

my_regex = re.escape(matches1[0])+r"\s*\=\s*\['(\w+)',*\s"  #['AngR'] from CHANNEL
matches = re.findall(my_regex, filetext)

Any help would be greatly appreciated

Thanks!

tricha122
  • 13
  • 2

0 Answers0