寻找某些词语模式 [英] Searching For Certain Pattern of Words

查看:175
本文介绍了寻找某些词语模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



是否有任何RegularExpression在1000个单词的描述中搜索特定单词或单词集,并返回包含该特定单词集的150个字符。


例如:

如果我有一组单词,如:"Disorders or Diseases必须被治愈"

我有100个单词的描述,其中单词组随机分布。

有什么方法可以提取150个单词的摘要,使其包含全部或任何"必须治愈的疾病或疾病"。字符串

任何帮助表示赞赏

提前感谢

解决方案

不确定我是否完全理解您的问题。您是否想拥有一串搜索词然后将这些词与输入字符串匹配?如果是这样,这里有一些代码可以做到这一点:




string input =" Heart不知道性别。它可以在一秒钟内毁掉我们的生活。攻击可能发生在所有年龄段......" ;;

string searchTerm =" Heart Attack" ;;

char [] delimiter = {''}

string [] searchTerms = searchTerm.Split(delimiter);

string format ="< b>


0< / b>" ;;

for(int i = 0; i< searchTerms.Length; i ++)
{

Regex rx = new Regex(" ; \b" + searchTerms +" \b");

Hi,

Is there any RegularExpression which searches for a particular word or set of words in a description of 1000 words and gets back 150 characters which contains that particular set of words.

for instance:

If i have a group of words like : "Disorders or Diseases have to be Cured"

and i have a description of 100o words where the group of words are spread randomly.

Is there any way that i can pull out my Abstract of 150 words so that it contains the all or any of the "Disorders or Diseases have to be Cured" string

Any help is appreciated

Thanks in advance

解决方案

Not sure if I completely understand your question. Do you wanrt to have a string of search words and then match any of these words with your input string? If so here is some code that can do that:



string input="Heart knows no gender. It can ruin our life in a second. Attack can happen at all the ages...";

string searchTerm = "Heart Attack";

char[] delimiter= {' '}

string[] searchTerms = searchTerm.Split(delimiter);

string format = "<b>


0</b>";

for(int i=0;i<searchTerms.Length;i++)
{

Regex rx = new Regex("\b"+searchTerms+"\b");


这篇关于寻找某些词语模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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