富文本框突出显示正则表达式匹配单词 [英] Rich text box highlight with Regex matching words

查看:285
本文介绍了富文本框突出显示正则表达式匹配单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我创建了一个项目来从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.


这篇关于富文本框突出显示正则表达式匹配单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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