fork download
  1. import re
  2. test = ['abc text_ abc',
  3. 'abc _text abc',
  4. 'abc text_textUnderscored abc',
  5. 'abc :_text abc',
  6. 'abc _text_ abc',
  7. 'abc __text__ abc']
  8. test_str = ' '.join(test)
  9. rx = re.compile(r'\b_(?:\w*_)?\b')
  10. print(rx.findall(test_str))
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
['_text_', '__text__']