user3664020 user3664020 - 1 year ago 189
Python Question

extract first three numbers from a string

I have strings like

"ABCD_ABCD_6.2.15_3.2"
"ABCD_ABCD_12.22.15_4.323"
"ABCD_ABCD_2.33.15_3.223"


I want to extract following from above

"6.2.15"
"12.22.15"
"2.33.15"


I tried using indices of numbers but cant use them since they are variable. Only thing constant here is the length of the characters appearing in the beginning of each string.

Answer Source

Another way would be this regex:

_(\d+.*?)_

import re
m = re.search('_(\\d+.*?)_', 'ABCD_ABCD_6.2.15_3.2')
m.group(1)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download