re.compile and very specific searches
John Machin
sjmachin at lexicon.net
Fri Feb 18 15:49:41 EST 2005
Diez B. Roggisch wrote:
>
> You could use another regular expressin, e.g. like this:
>
>
> rex = re.compile(r"^((\d)|(1\d{1,2})|(2[0-5]\d))$")
This approach would actually work without the need for subsequent
validation, if implemented properly. Not only as you noted does it let
"259" through, but also it doesn't cover 2-digit numbers starting with
2. Assuming excess leading zeroes are illegal, the components required
are:
\d
[1-9]\d
1\d\d
2[0-4]\d
25[0-5]
>
> This is of course only for one number. Extend it accordingly to the
ip4
> address format.
>
More information about the Python-list
mailing list