富文本框突出显示正则表达式匹配单词

问题描述:

大家好,我创建了一个项目来从SQL获取数据并在Richtextbox中显示,我可以突出显示用户在textbox1中输入的richtextbox中的单词。



要求是,很少有用户在单词中使用像*(例如:proje * t)这样的通配符。

需要使用正则表达式匹配Richtextbox中的单词,如

(项目,预计,投影等..)。



请帮助我。

Hi, I have created a project to get the data from SQL and display in Richtextbox, I am able highlight the words in richtextbox which user had entered in textbox1.

The requirement is, few users uses wildcard like * (eg: proje*t) in the words.
Need to highlight the words in Richtextbox using Regex matching the words like
(project, projected, projection etc..).

Please help me on the same.

这比第一眼看起来更复杂 - 正则表达式语法与普通windows通配符语法不同。

但是,它不应该是一个主要的工作: jous使用string.replace将通配符规范更改为正则表达式语法:

That is more complex than it looks at first glance - the regex syntax is different to the "normal" windows wildcard syntax.
However, it shouldn''t be a major job to handle: jous use string.replace to change the wildcard spec to regex syntax:
string rPartial = inp.Replace("*", ".*?");
string r = rPartial.Replace("?", ".");

那么你可以运行你的正则表达式来识别你需要突出显示的区域。

You can then run your regex to identify the areas you need to highlight.