Inspired by Regexp to match IP address, I thought of golfing the smallest Perl expression (not necessarily a regular expression) that, when using strict and warnings, evaluates to true if $_ is a valid numeric IPv4 decimal address.
Those addresses can be:
Here is the first naive attempt to get the ball rolling. It's 24 + 39 + 54 + 64 = 181 characters, easy to beat!
Update: It looks like I didn't make myself clear, when I said "smallest expression" I meant "smallest valid Perl expression", I didn't mean "regular expression"
# 1 2 3 4 5 6 #234567890123456789012345678901234567890123456789012345678901234 (/^(\d+)$/&&$1<256**4)|| (/^(\d+)\.(\d+)$/&&$1<256&&$2<256**3)|| (/^(\d+)\.(\d+)\.(\d+)$/&&$1<256&&$2<256&&$3<256**2)|| (/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/&&$1<256&&$2<256&&$3<256&&$4<256)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (Golf) Expression for matching numeric IP addresses
by BrowserUk (Patriarch) on Aug 06, 2004 at 18:12 UTC | |
|
Re: (Golf) Expression for matching numeric IP addresses
by hv (Prior) on Aug 10, 2004 at 13:32 UTC | |
|
Re: (Golf) Expression for matching numeric IP addresses
by Aristotle (Chancellor) on Aug 06, 2004 at 21:47 UTC | |
|
Re: (Golf) Expression for matching numeric IP addresses
by naChoZ (Curate) on Aug 10, 2004 at 12:26 UTC |