如何在c#中使用Regex计算特定单词的出现次数 [英] how to count occurrance of a specific word using Regex in c#

查看:124
本文介绍了如何在c#中使用Regex计算特定单词的出现次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 MatchCollection collection2 = Regex.Matches(range.Text, @ (\\ \\W | ^)U / S(\W | $))。 
count = collection2.Count;





我需要找到所有u / s。在我的文件中,我正在使用此代码...

实际上有41次发生,但这段代码只计算了15 ...

做什么,plz help

解决方案

));
count = collection2.Count;





我需要在我的文件中找到所有u / s。,我正在使用此代码...

实际上有但是这个代码只计算了15 ...

做什么,plz help


试试用

  string  pattern = Regex.Escape(  u / s。); 
MatchCollection collection2 = Regex.Matches(range.Text, @ (?:(?< = ^ | \ s)(?= \ S)|(?< = \S | ^)(?= \ s)) + pattern + @ (?:(?< = \ S)(?= \s |

)|(小于?= \s)(= \S |

MatchCollection collection2 = Regex.Matches(range.Text, @"(\W|^)u/s.(\W|$)");
               count = collection2.Count;



I need to find all the "u/s." in my file, i'm using this code...
in actual there are 41 occurrence but this code is counting only 15...
what to do, plz help

解决方案

)"); count = collection2.Count;



I need to find all the "u/s." in my file, i'm using this code...
in actual there are 41 occurrence but this code is counting only 15...
what to do, plz help


try with

 string pattern = Regex.Escape("u/s.");
MatchCollection collection2  = Regex.Matches(range.Text, @"(?:(?<=^|\s)(?=\S)|(?<=\S|^)(?=\s))" + pattern + @"(?:(?<=\S)(?=\s|


)|(?<=\s)(?=\S|


这篇关于如何在c#中使用Regex计算特定单词的出现次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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