Python regex to match IP-address with /CIDR

asdasdasd picture asdasdasd · Nov 19, 2010 · Viewed 9.3k times · Source
m = re.findall("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}",s)

How do I modify it so it will match not only IPv4, but also something with CIDR like 10.10.10.0/24?

Answer

atomizer picture atomizer · Nov 19, 2010

(?:\d{1,3}\.){3}\d{1,3}(?:/\d\d?)?