I’m trying to create a JAVA regex to test if specific options are set. At the moment I have [ks]?[zx]?[ap]? so it is either k, s or nothing, then z, x or nothing and at last a, p or nothing.
The only problem with this regex is it works only in this one order but it should work with all orders, because kza, azk, zka, kaz, akz and zak do the same thing.
Steel yourself – this answer reinforces regular expressions as a write-only language!
This can more clearly be written like so if you’re using Groovy (or Java 7) for multi-line strings:
This version matches each group, only if that group doesn’t appear somewhere later on in the string. This is a ‘zero width, look ahead assertion’.