如果之前没有特定字符,请匹配单词 [英] Match words if there isn't a specific character before

查看:69
本文介绍了如果之前没有特定字符,请匹配单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用正则表达式来执行语法突出显示。要突出显示关键字,我有以下表达式:

字符串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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆