如果之前没有特定字符,请匹配单词 [英] Match words if there isn't a specific character before
问题描述
我使用正则表达式来执行语法突出显示。要突出显示关键字,我有以下表达式:
字符串syntaxPattern = @"(\ bif \b)|(\ bwhile \b)|(\ bclassdef \ b)| (\bproperties\b)|(\bend\b)|(\bmethods\b)|(\bfunction\b)|(\belse\b)|(\bfor\\ \\ b)" ;;
这里的问题是,如果关键字在评论中,则不应突出显示。换句话说:如果关键字前面有'%',则不应突出显示。如何为此设置正则表达式?
感谢您的帮助!
(^ [^%] )*(\bif\b)|(\bwhile\b)|(\bclassdef\b)|(\bproperties\b)|(\bend\b)|(\ bmethods\b)|(\bfunction\b)|(\belse\b)|(\bfor\b)
I use regular expressions to perform syntax highlighting. To highlight keywords I have the following expression:
string syntaxPattern = @"(\bif\b)|(\bwhile\b)|(\bclassdef\b)|(\bproperties\b)|(\bend\b)|(\bmethods\b)|(\bfunction\b)|(\belse\b)|(\bfor\b)";
The problem here is that if the keyword is in a comment it shouldn't be highlighted. In other words: If there is a '%' before the keyword it should not be highlighted. How can I set up a regular expression for this?
Thanks for help!
(^[^%])*(\bif\b)|(\bwhile\b)|(\bclassdef\b)|(\bproperties\b)|(\bend\b)|(\bmethods\b)|(\bfunction\b)|(\belse\b)|(\bfor\b)
这篇关于如果之前没有特定字符,请匹配单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!