Bug in re.findall?

Richie Hindle richie at entrian.com
Fri Jul 4 07:14:20 EDT 2008


Hi Marcin,

> subnetlist="192.168.100.0 , 192.168.101.0"
> ipre=re.compile("([0-9]{1,3}\.){3}[0-9]{1,3}")
> 
> >>> ipre.findall(subnetlist)
> ['100.', '101.']

Correct - it returns the most recently captured text for your sole group.

> a=ipre.finditer(subnetlist)
> >>> a.next().group()
> '192.168.100.0'

Also correct, because match.group() returns the whole of the matched text.
If you wanted just your captured piece, you need this:

> >>> a.next().group(1)
> '100.'

Hope that helps!

-- 
Richie Hindle
richie at entrian.com
http://entrian.com



More information about the Python-list mailing list