BenF97 BenF97 - 1 year ago 68
Python Question

Regex to get number after matched pattern

I have created a regex pattern to match the following:

'x': 10.61 # Any number, can be negative


However, I would like to get only the number, and so have attempted the following:

re.findall("'x':\K\s[-+]?\d*\.*\d+", info)

But from what I understand
doesn't work on python.

Is there any alternative that would match e.g:

Answer Source

This should work:

info = "'x': 10.61"
items = re.findall("'x':\s([-+]?\d*\.*\d+)", info)
print(items[0]) # 10.61
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download