re.compile and very specific searches
Denis S. Otkidach
ods at strana.ru
Sat Feb 19 04:44:25 EST 2005
On Fri, 18 Feb 2005 13:14:28 -0500
rbt <rbt at athop1.ath.vt.edu> wrote:
> Is it possible to use re.compile to exclude certain numbers? For
> example, this will find IP addresses:
>
> ip = re.compile('\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}')
>
> But it will also find 999.999.999.999 (something which could not
> possibly be an IPv4 address). Can re.compile be configured to filter
> results like this out?
Try this one:
re.compile(r'\b%s\b' % r'\.'.join(['(?:(?:2[0-4]|1\d|[1-9])?\d|25[0-5])']*4))
--
Denis S. Otkidach
http://www.python.ru/ [ru]
More information about the Python-list
mailing list