ptx captures most of what i want. Because i am incompetent at combining many things into one regex) i created a second ptx1 regex that should capture the following character sequences ADDITIONALLY:
One Department, One foreign Department, Two office
text_list = [' something\npatternx: text_i_want One Department',' something patternx: text_i_want One foreign Department',' something\n patternx: text_i_want Two office']
text_list = ' '.join(map(str, text_list))
ptx = re.compile(r'(\s+something(?:\s+|\\n)*patternx:)(.*)(One\s+foreign)', flags = re.DOTALL)
ten = ptx.search(text_list)
try:
if ten:
ten = ten.group(2)
else:
ten = None
except:
pass
My question is: What do i need to do in order to get the (.*) or text_i_want content returned? I have the gut feeling that i need to access the eleven as if it were a list because it has so many capturing groups by eleven[0].group(1) in order to get first element from the list and get its second group. But that didnt work either.
You can think of text_list like this
text_list = ['...something\npatternx: text_i_want One Department',
'...something patternx: text_i_want One foreign Department',
'...something\n patternx: text_i_want Two office']
Update
text_list = [' something\npatternx: text_i_want One Department',' something patternx: text_i_want One foreign Department',' something\n patternx: text_i_want Two office']
text_list = ' '.join(map(str, text_list))
ptx = re.compile(r'\bsomething\s+patternx:(.*?)\b(?:One\s+(?:Department|foreign(?:\s+Department)?)|Two\s+office)\b', flags = re.DOTALL)
ten = ptx.search(text_list)
try:
if ten:
ten = ten.group(2)
else:
ten = None
except:
pass