I need a regex in jFlex to match a string literal, containing some characters, followed by a hyphen which is followed by a word. However, there are a few hardcoded exceptions. My jFlex version is 1.6.1
My regexes are:
SUFFIXES = labeled|deficient
ALPHANUMERIC = [:letter:]|[:digit:]
AVOID_SUFFIXES = {SUFFIXES} | !({ALPHANUMERIC}+)
WORD = ({ALPHANUMERIC}+([\-\/\.]!{AVOID_SUFFIXES})*)
String "MXs12-labeled"
should be tokenized into 'MXs12', '-', 'labeled'
(hyphen caught by different regex later), and "MXs12-C123"
into 'MXs12-C123'
as C123 is not on list of suffixes.
However, the token I obtain is "MXs12-labele"
- one letter short of the one forbidden by exception.
An obvious solution would be including additional non {ALPHANUMERIC}
character in the regex, but that would add this character to the match too.
Another solution seemed to be to use a negative lookahead, but they return a syntax error every time I try to parse them - jFlex seems not to supports it. (Flex seems do not support a regex lookahead assertion (the fast lex analyzer))
Does anyone know how to solve this in jFlex?