I am using the following regular expression:
if (input.matches("^[\\d\\s()\bAND\b\bOR\b.]+$")) {
// do something
}
My goal is to validate only numbers (int and decimal), spaces, ( ), dot, AND, OR. Everything else is not allowed. It seems like it works but I'm having problems with word boundary \bAND\b and \bOR\b Eg. I can't not enter ANDWE or EEE or any combination, but what I can do is AN or A. How do I only allow two words AND or OR in a string? They are optional in a string.
Input examples
0.10 AND 23 - valid
12 AND (15 OR 0.2) - valid
12 OR 190 - valid
12 AND AND 12 - valid
12 A 233 - invalis