I've been trying to get an efficient regex for IPv4 validation, but without much luck. It seemed at one point I had had it with (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?(.|$)){4}
, but it produces some strange results:
$ grep --version
grep (GNU grep) 2.7
$ grep -E '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?(.|$)){4}' <<< 192.168.1.1
192.168.1.1
$ grep -E '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?(.|$)){4}' <<< 192.168.1.255
192.168.1.255
$ grep -E '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?(.|$)){4}' <<< 192.168.255.255
$ grep -E '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?(.|$)){4}' <<< 192.168.1.2555
192.168.1.2555
I did a search to see if this had already been asked and answered, but other answers appear to simply show how to determine 4 groups of 1-3 numbers, or do not work for me.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…