I’m trying to create a regular expresion to match any word ( \w+ ) except true or false.
This is what I got so far is: \w+\s*=\s*[^true|^false]\w+
class Ntnf {
public static void main ( String ... args ) {
System.out.println( args[0].matches("\\w+\\s*=\\s*[^true|^false]\\w+") );
}
}
But is not working for:
a = b
a = true
a = false
It matches always.
How can I match any word ( \w+ ) except true or false?
EDIT
I’m trying to spot this pattern:
a = b
x = y
name = someothername
etc = xyz
x = truea
n = falsea
But avoid matching
a = true
etc = false
name = true
You can use:
So it matches as long as the whole string isn’t just “true” or “false”. Note that it can still start with one of those.
However, it may be more straightforward to use regular string comparisons.
EDIT:
The whole regex (without escaping) for your situation is:
It’s the same idea, except that we’re putting it in the equation form.