I have text like:
"abababba"
I want to extract the characters as a list between a
.
For the above text, I am expecting output like:
['b', 'b', 'bb']
I have used:
re.split(r'^a(.*?)a$', data)
But it doesn’t work.
Advertisement
Answer
The ^ and $ will only match the beginning and end of a line, respectively. In this case, you will get the desired list by using the line:
re.split(r'a(.*?)a', data)[1:-1]