fork download
  1. import re
  2. 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']
  3. text_list = ' '.join(map(str, text_list))
  4. rx = r'\bsomething\s+patternx:(.*?)\b(?:One\s+(?:Department|foreign(?:\s+Department)?)|Two\s+office)\b'
  5. print(re.findall(rx, text_list, re.DOTALL))
  6. # => [' text_i_want ', ' text_i_want ', ' text_i_want ']
  7.  
Success #stdin #stdout 0.03s 9412KB
stdin
Standard input is empty
stdout
[' text_i_want ', ' text_i_want ', ' text_i_want ']