From python-list Wed Sep 19 12:17:16 2007 From: "Dan Bar Dov" Date: Wed, 19 Sep 2007 12:17:16 +0000 To: python-list Subject: re question Message-Id: X-MARC-Message: https://marc.info/?l=python-list&m=119020428627458 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--===============1061843039==" --===============1061843039== Content-Type: multipart/alternative; boundary="----=_Part_28626_22133164.1190204236133" ------=_Part_28626_22133164.1190204236133 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline I'm trying to construct a regular expression to match valid IP address, without leading zeroes (i.e 1.2.3.4, 254.10.0.0, but not 324.1.1.1, nor 010.10.10.1) This is what I come up with, and it does not work. r'(^[12]?\d{0,2}\.){3,3}[12]?\d{0,2}' What am I doing wrong? Any common knowledge IP matching RE? Thanks, Dan ------=_Part_28626_22133164.1190204236133 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline I'm trying to construct a regular expression to match valid IP address, without leading zeroes (i.e
1.2.3.4, 254.10.0.0, but not 324.1.1.1, nor 010.10.10.1)

This is what I come up with, and it does not work.

r'(^[12]?\d{0,2}\.){3,3}[12]?\d{0,2}'

What am I doing wrong?
Any common knowledge IP matching RE?

Thanks,
Dan
------=_Part_28626_22133164.1190204236133-- --===============1061843039== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline -- http://mail.python.org/mailman/listinfo/python-list --===============1061843039==--