Question on regex
Felix Benner
felix.benner at imail.de
Sat Dec 23 08:08:08 EST 2006
Prabhu Gurumurthy schrieb:
> to fix this problem, i used negative lookahead with ip pattern:
> so the ip pattern now changes to:
> \d{1,3}(\.\d{1,3}){3}(?!/\d+)
>
> now the problem is 10.150.100.0 works fine, 10.100.4.64 subnet gets
> matched with ip pattern with the following result:
>
> 10.100.4.6
>
> Is there a workaround for this or what should change in ip regex pattern.
>
I think what you want is that neither /d+ nor another digit nor a . follows:
\d{1,3}(\.\d{1,3}){3}(?!(/\d)|\d|\.)
This way 10.0.0.1234 won't be recognized as ip. Neither will 23.12.
which could be a problem if an ip is at the end of a sentence, so you
might want to omit that.
More information about the Python-list
mailing list