I am searching a string, there will be a line beginning with ssid and I need to find the word directly after that. So an example is "ssid home", home would be the word I wish to return. I have done this in a roundabout way, seems very messy, what way should I do this, a regex perhaps or is there a way to tidy up what I have done?
a = """
!
interface blah
a
ssid test
v
v
"""
b = a.split("\n")
matches = [x for x in b if "ssid" in x]
matches = [i.split() for i in matches]
print matches[0][1]
a = """
!
interface blah
a
ssid test1
v
ssid test2
v
ssid test3
"""
p = r'(?<=ssid )\S+' # non-whitespace character chunk after ssid
match = re.findall(p, a)
This will give you: ['test1', 'test2', 'test3']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With