Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Re: Bug in re.findall?

Question posted by: Richie Hindle (Guest) on July 4th, 2008 12:55 PM
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
Join Bytes!
http://entrian.com
 
Not the answer you were looking for? Post your question . . .
189,879 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors