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 find all every element between text Python

I’d like to know how to find characters in between texts in python. What I mean is that you have for example:

cool_string = "I am a very cool string here is something: not cool 8+8 that's it"

and I want to save to another string everything in between something: to that’s it.
So the result would be:

soultion_to_cool_string = ' not cool 8+8 '

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 :

You can use str.find()

start = "something:"
end = "that's it"

cool_string[cool_string.find(start) + len(start):cool_string.find(end)]

If you need to remove empty space str.strip()

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