Code
using System.Text.RegularExpressions;
Code
static void Main(string[] args)
{
string words = @" hi _wel@come ti3 TT to china?";
//#匹配由26个英文字母组成的单词
Regex r = new Regex(@"(?x) #消除模式中的非转义空白和并启用由#标记的注释
\b #匹配字符类外的字边界
((?<=\s)|^) #前面空白或顶格
([a-zA-Z]+) #由1个或多个(26个英文字母里的字母)组成的单词
(?=\s|[.!?]?$) #后面接空白或若是句子的结尾,则可接标点符号
\b #匹配字符类外的字边界
");
MatchCollection mc = r.Matches(words);
foreach (Match m in mc)
{
Console.WriteLine(m.Value);
}
}
/*
* hi
* TT
* to
* china
* */
posted @
2008-08-02 23:21
.net's
阅读(
1129)
评论()
编辑
收藏
举报