JavaScript RegExp 匹配“%.*”,但不匹配“\%.*”
我正在尝试改进 Alex Gorbatchev 的 SyntaxHighlighter 使用的 LaTeX 画笔。我在网上找到的画笔正确匹配以 %
开头的 LaTeX 注释,但是当转义 \%
时就出错了;即,它认为后者也是一条评论。
画笔中使用的正则表达式是%.*
。我认为负向后看 (? 会起作用,但 JavaScript 不支持这个......还有其他想法吗?
谢谢 :)
I am trying to improve upon the LaTeX brush used by Alex Gorbatchev's SyntaxHighlighter. The brush I found online correctly matches LaTeX comments, which start with %
, but gets it wrong when it is escaped \%
; i.e., it thinks the latter is also a comment.
The RegExp used in the brush is %.*
. I figured that a negative lookbehind (?<!\\)%.*
would work, but JavaScript doesn't support this... Any other ideas?
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想你可以使用这个
([^\\]|^)%.*
说它不是 \ 或者它是行的开头i guess you could use this
([^\\]|^)%.*
saying either its not \ or it is start of line您是否尝试
过匹配字符串的开头或非
\
字符...?Have you tried
To match the start of the string or a non
\
character...?