jflex: Why does this regex match?
in my lexer I wrote the following regex:
"///"\s*[^@\s].*
I executed byacc/j in debug mode and it states that the following line matched the regex.
But why does this regex match this line?/// @Service( version="1.0.0" )
I also tried "///"\s*[^\@\s].*
, in case @
is a special character, but it also matches. o.O
I thought my regex would match only a string that starts with ///
followed by optional whitespaces. Than any non-whitespace character except @
must come, followed by any characters.
Edit: I'm sorry I meant the regex is used within jflex, not byacc/j.
Workaround: In the jflex documentation I didn't find any \s
escape sequence, so I tried this regex "///"[ \t\f]*[^@ \t\f].*
and it worked. It seems that the \s
escape character is not supported a开发者_如何学运维nd silently ignored by jflex.
The workaround is correct, before version 1.5.0 \s
was not a special escape sequence in JFlex, and just meant the letter s
. Starting with version 1.5.0, the regexp should work as expected.
@
is not a special character and doesn't need escaping.
Is the \ being escaped so that the regex being passed is actually "///"s[^@s].*
Try double escaping so you use "///"\\s[^@\\s].*
精彩评论