Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to extract the value between the key using RegEx?

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

re.split(r'^a(.*?)a$', data)

But it doesn’t work.

>Solution :

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]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading