This will solve your problem:
((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?!\d)\.??){4}
Anchor (see test results):
^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$
Test results:
// Valid IP addresses // 1.2.3.4 // 255.255.255.255 // Invalid IP addresses // 1.2.3 // 1.2.3. // .1.2.3 // 1.2.3.4.5.6.7.8 (use anchors ^ and $ to skip these if needed, since 1.2.3.4 and 5.6.7.8 will still be captured) // 999.999.999.999 // 299.299.299.299 // 001.002.003.004 (these use octal notation, not decimal)
An anchored regular expression will not match the inner text only if you want a very strict match for a string that should only contain IP
Update:
Real time results here
source share