Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to select all character between underscores

I am trying to write a regular expression to select all characters between underscores. I end up with _([^_]+)_ but it does not match all the groups,

String : abc_bca_vag_hag_bag output : bca vag hag

can someone help with this?

like image 815
Abhishek Avatar asked Nov 23 '25 05:11

Abhishek


1 Answers

I used split function and select every elements except first one and last one:

st = 'abc_bca_vag_hag_bag'
lis = st.split('_')[1:-1]
# output  ['bca', 'vag', 'hag']
like image 167
mastisa Avatar answered Nov 25 '25 18:11

mastisa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!