huge expression
i installed linux on my machine and am trying to figure out these expression thingies, but this one stumps me, what is it doing?
grep "^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$
Off the top of my head, it looks like it''s a regular expression to match a dotted decimal IP address.
22:46 |aftermath| This is from a forum, but what the heck could this regex mean? "^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$ (http://gamedev.net/community/forums/topic.asp?topic_id=209389)22:47 | hroc| aftermath - I think it''s an IP address22:48 | Rias| it would match a sequence of: 1-3 numbers of 0-9, a dot, 1-3 numbers of 0-9, a dot, 1-3 numbers of 0-9, a dot, 1-3 numbers of 0-922:48 | Rias| it''s a bad regex for matching an ip address
Makes sence to me.
(copied with permision)
Rate me up.
I concur that it is a regex to detect an IP like number. I also think its broken as an IP detector, as IP addresses can be no larger that 255.255.255.255, but this will detect up to 999.999.999.999.
Of course, it probably doesn''t matter as no other number scheme I know of has a similar pattern, and presumably whatever created the IP would follow the rules. I just mention it because I recently taught a TCP/IP course and feel the need to be specific.
Of course, it probably doesn''t matter as no other number scheme I know of has a similar pattern, and presumably whatever created the IP would follow the rules. I just mention it because I recently taught a TCP/IP course and feel the need to be specific.
quote:Famous last words.
Original post by debaere
...presumably...
The point being that assumption is the mother of all f**k-ups. See buffer exploit.
quote:
Famous last words.
The point being that assumption is the mother of all f**k-ups. See buffer exploit.
This is indeed true. Assumptions can come back to bite you in very uncomfortable places.
The upside to that regex catching invalid IPs is that you can use it, with other checking, to catch errors... so its not all bad.
quote:Scroll down a bit. Using additional code where less suffices (without abusing "cleverness") is a bug waiting to happen. You have to keep more code in sync, you have more code to verify, you have more code to debug...
Original post by debaere
The upside to that regex catching invalid IPs is that you can use it, with other checking, to catch errors... so its not all bad.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement