Regular expression for validating ip address

22-Dec-2016 22:12

To belabor the obvious: IP addresses are 32 bit values written as four numbers (the individual bytes of the IP address) separated by dots (periods).Each of the four numbers has a valid range of 0 to 255. d))))|:))|(([0-9A-Fa-f]:)(((:[0-9A-Fa-f]))|((:[0-9A-Fa-f]):((25[0-5]|2[0-4]d|1dd|[1-9]? Every computer connected to the Internet is identified by a unique four-part string, known as its Internet Protocol (IP) address.For the purpose of this discussion, I'll restrict myself to the common subset of the regular expression languages shared by perl, JScript, and the .NET Framework, and I'll assume ECMA mode, wherein This is nice as far as it goes, but it erroneously accepts strings like "448.90210.0.65535".

You can test them out in your browser using the excellent Regex Pal site.

The status of a command/function is stored in the bash variable "$? variable so that rather than parsing words as whitespace separated items, bash parses them as dot separated.

Putting the value of the subject IP address inside parenthesis and assigning it to itself thereby turns it into an array where each dot separated number is assigned to an array slot.

e.g., it won't match This expression will not match IP addresses with more than 4 octets.

e.g., it won't match welcome at superuser. To help people understanding differences between them, please edit your answer and explain what makes it better / different from the other ones. s* [Updated: 6/Apr/2015 – fixed to resolve the problem pointed out by Pirabarlen in the comments] ^s*((([0-9A-Fa-f]:)([0-9A-Fa-f]|:))|(([0-9A-Fa-f]:)(:[0-9A-Fa-f]|((25[0-5]|2[0-4]d|1dd|[1-9]? d)))|:))|(([0-9A-Fa-f]:)(((:[0-9A-Fa-f]))|:((25[0-5]|2[0-4]d|1dd|[1-9]?