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

python – splitting string by characters

I have a string which looks as such:

my_str = '15(1)(635)(634)(582)(583)'

How do I get an array of values from the string?

[15,1,635,634,582,583]

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

>Solution :

This can easily be solved with a simple regex : \d+

import re

my_str = '15(1)(635)(634)(582)(583)'
print([int(i.group()) for i in re.finditer(r'\d+', my_str)])

output:

[15, 1, 635, 634, 582, 583]
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