Reputation: 34356
I have a string like this:
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT evictions 0
STAT reclaimed 0
END
I'm trying to get the value of curr_items, so far I've got
out = telnet.read_until("END")
req = re.search("curr_items", out).group(0).split()[0]
Which returns curr_items, how do I get the value?
Thanks
Upvotes: 1
Views: 2581
Reputation: 429
try:
req = int(re.search("(?<=curr_items)\s*([\d]*)", out).group(0))
except:
# No value was found.
req = defaultValue
Upvotes: 1
Reputation: 262919
You can add a capture group matching the value to your regex:
>>> int(re.search("curr_items (\d+)", out).group(1))
0
Upvotes: 6