[英]JavaScript RegExp to match “%.*”, but not “\%.*”
I am trying to improve upon the LaTeX brush used by Alex Gorbatchev's SyntaxHighlighter. 我正在尝试改进Alex Gorbatchev的SyntaxHighlighter使用的LaTeX笔刷。 The brush I found online correctly matches LaTeX comments, which start with %
, but gets it wrong when it is escaped \\%
; 我在网上找到的画笔与LaTeX注释正确匹配,该注释以%
开头,但是在转义\\%
时弄错了。 ie, it thinks the latter is also a comment. 即,它认为后者也是评论。
The RegExp used in the brush is %.*
. 笔刷中使用的RegExp为%.*
。 I figured that a negative lookbehind (?<!\\\\)%.*
would work, but JavaScript doesn't support this... Any other ideas? 我认为在(?<!\\\\)%.*
使用负向后看是可行的,但是JavaScript不支持此方法...还有其他想法吗?
Thanks :) 谢谢 :)
我猜你可以用这个([^\\\\]|^)%.*
说它不是\\或它是行的开始
Have you tried 你有没有尝试过
([^\\]|^)%.*
To match the start of the string or a non \\
character...? 要匹配字符串的开头还是非\\
字符...?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.