需求:
从一段字符串文本中获取所有中文字符。
核心代码,如下:
//asp.net正则提取中文
//edit by www.jb200.com
public static string GetChineseWord(string oriText)
{
string x = @"[u4E00-u9FFF]+"; //正则
MatchCollection Matches = Regex.Matches(oriText, x, RegexOptions.IgnoreCase);
StringBuilder sb = new StringBuilder();
foreach (Match NextMatch in Matches)
{
sb.Append(NextMatch.Value);
}
return sb.ToString();
}
代码说明:
注意以上正则表达式:[u4E00-u9FFF]+,即是匹配所有中文。