Python Regex to detect underscore between letters

  python

How do I make a regex in python that returns a string with all underscores between lowercase letters?
For example, it should detect and return: ‘aa_bb_cc’ , ‘swd_qq’ , ‘hello_there_friend’

But it should not return these: ‘aA_bb’ , ‘aa_’ , ‘_ddQ’ , ‘aa_baa_2cs’

My code is ([a-zA-Z]+_[a-zA-Z]+)+ , but it returns only one underscore. It should return all underscores seperated by lowercase letters.

Thank you

Source: Python Questions

LEAVE A COMMENT