Regex equivalent to XOR

1594 views regex

I am trying to come up with a regex that would accept any of the values below combined, except when NONE is present. Something similar to an XOR where if NONE is present nothing else would be accepted, and vice-versa.

This is what I have so far...but it doesn't really enforces the mutual exclusivity of NONE:


Any suggestions?

Thank you!

answered question

Which regex program do you use

Hi Poul, I am using this regex to filter allowable content on a Splunk dashboard. So far I've been using to check my regexes.

Could you please provide possible strings for processing? It's not clear how is the NONE can be combined (if it can) with other values

Hi Aleksandr. In this case here the client can enter the category of their product...So the product category could be FOO|BAR or FOO|BAR|SPAM or SPAM but once they enter NONE, meaning that it doesnt fall in any categoy, they wont be allowed to enter any other values. So NONE should always be by itself. I hope I made it a little more clear. Thank you!

So the whole string is either NONE or one of FOO, BAR, SPAM?

1 Answer


You can use this regex:


It starts by a negative looking ahead for: any number of any char followed by 'NONE'.

If this test fails (NONE found) then the match will be empty. If no 'NONE' is found, it moves on and matches: From start of string any number of any char followed by any of your Words. This part is repeated.

posted this

Have an answer?


Please login first before posting an answer.