Dimebag Dimebag - 1 year ago 82
Python Question

Regex pattern within text

I have a long string of data which looks like:


Notice that the '12345.123' pattern is the same. I want to split the string on it using python (so

What would be the appropriate regex?


does not work; I presume it expects whitespace around it(?).

Answer Source

Just escape ., and you are done:


You can use Regex token \d as a shorthand for [0-9].


>>> re.split(r'\d{5}\.\d{3}', 'dstgfsda12345.123gsrsvrvsdfcsd23456.234tsrsd')
['dstgfsda', 'gsrsvrvsdfcsd', 'tsrsd']
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download