import rerx = r"(?:\b|(?<=_))word(?=\b|_)"s = "some_word_here and a word there"print(re.findall(rx,s))
Standard input is empty
['word', 'word']
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!