查找单词的正则表达式 [英] Regular expression for finding a word
本文介绍了查找单词的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个很长的字符串作为输入,我想计算该字符串中的单词数.
I have a long string of characters as input and I want to count the number of words in that string. How can I do it through regular expression?
推荐答案
Try:
Try:
Regex word = new Regex(@"\w+");
string data = "The quick brown fox jumps over the lazy dog.";
Console.WriteLine(word.Matches(data).Count);
获取 Expresso [ ^ ]-它是免费的,它检查并生成正则表达式.
Get a copy of Expresso [^] - it''s free, and it examines and generates Regular expressions.
string Input;
Input=Console.ReadLine();
string[] Output=Input.Split(' ');
Console.WriteLine("No of Words in Given String is {0}",Output.Length.ToString());
这篇关于查找单词的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文