Title |
Test
Find
Pattern Title
|
Expression |
\b(([01]?\d?\d|2[0-4]\d|25[0-5])\.){3}([01]?\d?\d|2[0-4]\d|25[0-5])\b |
Description |
Most Concise RegExp for matching Decimal IPs. If nothing else, it'll make your code easier to read. (And I know that \d?\d is \d{1,2} but that's 2 extra characters.)
--Update: darkone noticed 8 characters could be shaved down. I've edited it to reflect this. Thanks, darkone! |
Matches |
217.6.9.89 | 0.0.0.0 | 255.255.255.255 |
Non-Matches |
256.0.0.0 | 0978.3.3.3 | 65.4t.54.3 |
Author |
Rating:
Sean Schricker
|
Source |
|
Your Rating |
|
Title: dfg
Name: dfg
Date: 6/13/2008 10:56:42 AM
Comment:
sdf
Title: Buggy
Name: Jrf
Date: 9/21/2005 2:48:43 PM
Comment:
I believe this regex to be buggy.
It okays the following ip-address while it shouldn't (note the leading zeros):
255.255.255.02
02.234.2.1
Title: Failure
Name: Duke Nukem
Date: 9/30/2004 4:34:40 AM
Comment:
Caution: 1.2.3.4.5 matches also. Use ^...$ instead of \b...\b
Title: another approach
Name: darkone
Date: 9/17/2004 11:38:27 AM
Comment:
([01]?\d?\d|2[0-4]\d|25[0-5])
(matches one number) is a little bit shorter and should also do the job.
Title: regex match help
Name: sanjay
Date: 7/13/2004 11:58:12 AM
Comment:
I want to match a string which is not of a certain length say between 2 and 20 and it should not contain numbers or special characters except [. -]. I'm not able to find a pattern That will match a string NOT of a certain length.