开发者

jflex: Why does this regex match?

开发者 https://www.devze.com 2023-03-29 14:52 出处:网络
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.

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].*

0

精彩评论

暂无评论...
验证码 换一张
取 消