Richard Bucker

regex for IP address matching

Posted at — Jan 3, 2013

If you’re looking to splice an IP address from a document and there is a 100% chance that the IP address is properly formatted then why the F**k would you want a regex like this:

”^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]).){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])quot;
In the worst case the regex might look like:

”^([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})$”
But even this is abusive.