GeekZilla
IP Address regular expression
string pattern = @"\b(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]?)\b"
Paul is the COO of kwiboo ltd and has more than 20 years IT consultancy experience. He has consulted for a number of blue chip companies and has been exposed to the folowing sectors: Utilities, Telecommunications, Insurance, Media, Investment Banking, Leisure, Legal, CRM, Pharmaceuticals, Interactive Gaming, Mobile Communications, Online Services.
Paul is the COO and co-founder of kwiboo (http://www.kwiboo.com/) and is also the creator of GeekZilla.
Comments
Shatheesh said:
Thanks... It works...
kamal said:
Thanks for the Regex ..
Could you also include regular expression strings for other validations too,generally not found over net.
Thanks in advance!
phayman said:
You can find more here : http://www.geekzilla.co.uk/BrowseExpressionArchive.htm
Paul said:
It appears that the regex does not consider Ipv6
masterik said:
I've found another one at http://www.regular-expressions.info/examples.html:
\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
Wieland K said:
thank you! works great
steve said:
Thanks. You saved me a lot of time and trouble!
a++ said:
try this:
^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$
immeëmosol said:
Wouldn't your expression allow for:
000.000.000.000 ?
I do this to check if I am on my home-server (PHP):
preg_match('/^127(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[0-9]?)){2}\\.[1-9][0-9]{0,2}$/' , $SERVER['SERVERADDR'])
Regexes are good stuff.
Haider said:
Thanks Great working...
haidiva said:
HI , I want regular expre.. for ip address with wild card support .
Can any body help me on this .
ffatheranderson said:
Hi i won't to fix the "zero" and "255" ending ip address allowing
Bellow the rgex that don't allow addresses like "x.x.x.255" or "x.x.x.0" it is good for IP address as is.
^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){2}(\.([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4]))$
And this regex (was sended by steve(thanx you very useful)) good for check network address or multicast addressing like x.x.x.255" or "x.x.x.0.
^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$
Aiswaryam said:
Hello Paul,
Can you please tell me how to add regex express to whitelist pw-admin folder access for a range of ip address in nginx for our website http://www.freezonal.com/ which is using nginx?
narcisisimus said:
Hey, but all the possibilities don't cover xx.xxx.xxx.xx ? why?
Nguy?n Trung Tín said:
ex: ip:port xx.xx.xx.xx:xxxx how to ?