What regex can I use to match any valid IP-address represented in dot-decimal notation?
相关问题
- $ENV{$variable} in perl
- IPAddress.[Try]Parse parses 192.168 to 192.0.0.168
- Improve converting string to readable urls
- Is it possible to pass command-line arguments to @
- Regex to match charset
相关文章
- Optimization techniques for backtracking regex imp
- Regex to check for new line
- Allow only 2 decimal points entry to a textbox usi
- Running a perl script on windows without extension
- How to resolve hostname to an ip address in node j
- Comparing speed of non-matching regexp
- Can NOT List directory including space using Perl
- Regular expression to get URL in string swift with
CPAN is your friend: Regex::Common or Net::IP::Match::Regexp.
Not sure why I don't see this one around anywhere, it's short, concise, and awesome.
For IPv4 in an A.B.C.D (decimal) format, as a one-liner:
(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])
If nothing follows the address on the line, it can be contracted to:
(?:(?:[01]?\d?\d?|2[0-4]\d|25[0-5])(?:\.|$)){4}
Have fun.
I like this one ... pretty much as Steve Hajducko's but using quoted reg ex which rooooock!
I went for an interview at Arm in Cambridge, UK. They asked me to write one on the board and I wrote some lame one .. and later ... brooding on my poor attempt set out to make a better one. Driven by failure? Or maybe just really irritated by it. I still got the job :)