Reputation: 13
String = """bob
123 -- things
stuff after that line"""
I need to get " things". I have tried
def InBetween(Substring1, Substring2, String):
return String[(String.index(Substring1)+len(Substring1)):String.index(Substring2)]
Stuff = InBetween("--", "\n", String)
But this gives me a ValueError due to the fact that it can not get any results any way to do this?
Upvotes: 1
Views: 1316
Reputation: 1573
Using string methods:
for string in text.splitlines():
if ' -- ' in string:
print(string.strip().split(' -- ', 1)[1])
Upvotes: 1
Reputation: 12015
Use re.search
>>> re.search(r'--(.*)', String).group(1)
' things'
Upvotes: 1