I'm trying to write a string matching rule in ANTLRWorks, and I need to match either escaped quotes or any non quote character. I can match escaped quotes but I'm having trouble with the other part: ~'\'' | ~'\"'
will end up matching everything and ~'\'\"'
seems to be ignored by the grammar generator (at least the visual display). What sequence of characters will get me what I want?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Try something like this:
StringLiteral
: '"' (EscapeSequence | StringChar)* '"'
;
EscapeSequence
: '\\' ('"' | '\\')
;
StringChar
: ~('"' | '\\')
;