简体   繁体   中英

JavaScript RegExp to match “%.*”, but not “\%.*”

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 \\% ; ie, 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 :)

我猜你可以用这个([^\\\\]|^)%.*说它不是\\或它是行的开始

Have you tried

([^\\]|^)%.*

To match the start of the string or a non \\ character...?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM