Connecting Tech Pros Worldwide Forums | Help | Site Map

Re: Bug in re.findall?

Richie Hindle
Guest
 
Posts: n/a
#1: Jul 4 '08
Hi Marcin,
Quote:
subnetlist="192.168.100.0 , 192.168.101.0"
ipre=re.compile("([0-9]{1,3}\.){3}[0-9]{1,3}")
>
Quote:
Quote:
>ipre.findall(subnetlist)
['100.', '101.']
Correct - it returns the most recently captured text for your sole group.
Quote:
a=ipre.finditer(subnetlist)
Quote:
Quote:
>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:
Quote:
Quote:
Quote:
>a.next().group(1)
'100.'
Hope that helps!

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

Closed Thread