Regular Expressions?

Padraig Brady Padraig at Linux.ie
Fri Nov 29 05:12:38 EST 2002


KrayZee--J wrote:
> Is the Regular Expressions module really buggy or is it just me? Almost
> every expression I type in gives an error. Many expressions which I have
> tested and work in JScript give errors in python.
> 
> I want to make a RE which will match an IP address. This one works in
> JScript:
> 
> (\d{1,3}\.){3}\d{1,3}
> 
> In python it works but matches only 1 digit for the last octet of th IP ie.
> 192.168.0.100 becomes 192.168.0.1
> 
> Any suggestions would be appreciated.
> 
> John
> 
> 

$ import re
$ ips = "192.168.0.100sadfasf192.168.0.101adads324.23asdf192.168.0.102"
$ re.findall("(?:\d{1,3}\.){3}\d{1,3}", ips)
['192.168.0.100', '192.168.0.101', '192.168.0.102']

Pádraig.




More information about the Python-list mailing list