【发布时间】:2020-02-06 02:03:38
【问题描述】:
如何正确正则表达式 Rockstar Language 中的正确变量?
我正在为 vscode 写 syntax highlight extension。但它与字符串文字有点冲突,关键字“says”之后的任何内容都应该是字符串。 但是当与大写单词结合时,它会被检测为适当的变量。
这是我的正则表达式:
(?!(Say|Shout|Whisper|Scream|Listen( to)?|Put|If|Until|Build |Take it to the top|Knock |While|Continue|Break it down|My|Your|A|An|The)\\s)\\b((?<!says .*)([A-Z][a-zA-Z]+\\s?)+)\\b($|\\s)
问题是,非固定长度的lookbehind (?<!says .*) 在vscode 中无法用于解析语法。
Example code snippet on regex101
那么如何做到这一点呢?关于如何不使用该lookbehind的一些想法? 重点是在
Eleanor Rigby says Hello San Francisco
Eleanor Rigby 应该是可变的
says 应该是赋值
Hello San Francisco 应该是字符串
但如果不向后看,它会将Hello San Francisco 视为变量。
【问题讨论】:
标签: javascript regex visual-studio-code vscode-extensions