I am using Python pexpect to run a command and get some output from a remote server. The output it gives me (s.before) that I am trying to parse looks like the below (note that it includes the command that is being run as well as the output, the output of the command is from “LMS IP Address” onwards:
”
show ap details wired-mac xx:xx:xx:xx:xx:xx | include “St x08atus,Group,Type,LMS”nrLMS IP Address x.x.x.xrnGroup ap-group-namernStatus DownrnAP Type 505rn(aaa-bb-cc) *[mynode]
“
I already get various bits of info from this by using re.search (eg the AP Type) but I want to also get the Status. The complication is that Status can be more than ‘Down’ or ‘Up’, there are various other strings that could be here potentially containing punctuation characters, spaces etc. So I thought I could just do a match on any character (.+) and that it would only match up to the first rn. But that doesn’t work even if I add the re.M flag. I guess it’s not treating the rn as a newline but just as part of the string? This is my attempt to match:
status = re.search(‘Status +(.+)’,str(s.before),re.M)
‘status’ is then:
DownrnAP Type 505rn(aaa-bb-cc) *[mynode] ‘
“Down” is what I am after (in this case, but as mentioned it can be other values), so the match starts in the right place. But how can I match just up to the first rn and still be fairly liberal with what I am matching on?
Guy
1