McLeodx McLeodx - 3 months ago 3x
Python Question

How to find substrings in a string that end when they reach a character pattern (Python)

I have one long string which is dozens of urls. Is there a non-regex way to turn this into a list of urls, starting with the pattern

and ending each substring when
is found a second time?</a>

It's one long string without breaks.


Just try this:

" http".join(url.split("http")).split()

>>> url = "</a>"
>>> " http".join(url.split("http")).split()
['', '', '', '', '', '', '', '</a>', '']

Essentially this just adds a space before every "http" then splits by " ".