views:

114

answers:

2

What is a regex that can find a routable IPv4 addresses only? EG, does not match 192.0.2.1/24, 127.0.0.1, etc. Google seems to only find the all too common 'is an ip address' regex.

+2  A: 

Trying to implement business rules in a regex is a bad idea.

Just parse the IP address, and check whether it satisfies your criteria in code.

Anon.
A: 

You can't do this in a regex anyway, not efficiently. Parse it, then check against the special-case addresses (multicast, RFC 1918, etc).

Andrew McGregor