I've recently written about using bash arrays and bash regular expressions, so here's a more useful example of using them to test IP addresses for validity.

You can get remove() from Iterator to remove an element, while while Enumeration does not have remove() method. s* [Updated: 6/Apr/2015 – fixed to resolve the problem pointed out by Pirabarlen in the comments] ^s*((([0-9A-Fa-f]:)([0-9A-Fa-f]|:))|(([0-9A-Fa-f]:)(:[0-9A-Fa-f]|((25[0-5]|2[0-4]d|1dd|[1-9]? d)))|:))|(([0-9A-Fa-f]:)(((:[0-9A-Fa-f]))|:((25[0-5]|2[0-4]d|1dd|[1-9]? d)))|:))|(([0-9A-Fa-f]:)(((:[0-9A-Fa-f]))|((:[0-9A-Fa-f])? Imagine you were maintaining a program and stumbled across this regular expression.How long would it take you to figure out what it did?

regular expression for validating ip address-2regular expression for validating ip address-29regular expression for validating ip address-49

One thought on “regular expression for validating ip address”