-2
    ip = 'The management ip is 10.0.55.0 and the remote ip is 192.167.13.4.\n1.1.22.1 Random sentence'
    pat = re.compile('(\d{1,3}\.){3}')                                                          
    ips = re.findall(pat,ip)
    >>> ips                                                                                          
    ['55.', '13.', '22.']

I would have expected that the output be ['10.0.55.','192.168.13.','1.1.22.']

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
kpd_86
  • 81
  • 1
  • 1
  • 5

1 Answers1

-1

findall returns the contents of any capturing match groups, if you have any - which you do. Change the match group to non-capturing:

pat = re.compile('(?:\d{1,3}\.){3}')
psmears
  • 26,070
  • 4
  • 40
  • 48