regexjflex

How to match something not defined


if I have defined something like that

COMMAND         = "HI" | "HOW" | "ARE" | "YOU" 

How can i say "if u match something that is not a COMMAND"?..

I tried with this one

[^COMMAND]

But didn't work..


Solution

  • As far as I can tell this is not possible with (current) JFlex.

    We would need an effective tempered negative lookahead: ((?!bad).)*

    There are two ways to do a negative lookahead in JFlex:

    Otherwise, you may get some ideas from this answer (specifically the lookaround alternatives): https://stackoverflow.com/a/37988661/8291949