Organizational Research By

Surprising Reserch Topic

How to Match IP /IPv4 Addresses with Regular Expressions


If you want to check whether a certain string represents a valid IPv4 address in 255.255.255.255 notation, try one of these examples from Regular Expressions.

asked Sep 13, 2013 in Regular-exp by ashish singh
edited Sep 12, 2013 by ashish singh
0 votes
28 views



Related Hot Questions

1 Answer

0 votes
Simple regex to check for an IP address:
 
^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$
 
 
Accurate regex to check for an IP address:
 
^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}↵
 
(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
 
 
Simple regex to extract IP addresses from longer text:
 
\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b
 
 
Accurate regex to extract IP addresses from longer text:
 
\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}↵
 
(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
 
 
 
Simple regex that captures the four parts of the IP address:
 
^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$
 
 
 
 
Accurate regex that captures the four parts of the IP address:
 
^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.↵
 
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.↵
 
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.↵
 
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
 
 
 
answered Sep 13, 2013 by ashish singh
edited Sep 12, 2013

...