fork download
  1. import re
  2. line = "some text #foo test text #bar another text#error text #foo one more text"
  3. tag_list = ('#foo', '#bar')
  4.  
  5. tags = '|'.join(tag_list)
  6. res = re.findall(f'((?:{tags}).+?)(?={tags}|$)', line)
  7.  
  8. print(res)
Success #stdin #stdout 0.03s 9572KB
stdin
Standard input is empty
stdout
['#foo test text ', '#bar another text#error text ', '#foo one more text']