This question already has an answer here:
How do I find a string between two substrings ('123STRINGabc' -> 'STRING'
)?
My current method is like this:
>>> start = 'asdf=5;'
>>> end = '123jasd'
>>> s = 'asdf=5;iwantthis123jasd'
>>> print((s.split(start))[1].split(end)[0])
iwantthis
However, this seems very inefficient and un-pythonic. What is a better way to do something like this?
Forgot to mention:
The string might not start and end with start
and end
. They may have more characters before and after.
This I posted before as code snippet in Daniweb:
gives
must show: here0, here1, here2
the regex is better but it will require additional lib an you may want to go for python only
My method will be to do something like,
This seems much more straight forward to me: