Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

split string python with changing indicator

lets say I have a string .

a = '!!!!!!a1@@@@@@a2&&&&&&a3::::'

It naturally splits by: a1,a2 and a3 to

['!!!!!!','@@@@@@','&&&&&&','::::']

I want to use the split function, something like:

>>> a.split('a*')

The * indicates that it doesn't matter what character comes after a. Is there an immediate way to do this?

like image 219
user552231 Avatar asked Sep 26 '26 20:09

user552231


1 Answers

s = '!!!!!!a1@@@@@@a2&&&&&&a3::::'
import re

print(re.split(r'a[0-9]+', s))
like image 200
Menglong Li Avatar answered Sep 28 '26 08:09

Menglong Li



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!