正則表達式匹配中文與雙字節(jié)的代碼
更新時間:2010年11月17日 22:08:16 作者:
匹配中文字符與匹配雙字節(jié)字符的代碼,需要的朋友可以參考下。
匹配中文字符
[\u4e00-\u9fa5]
C#
class Class1
{
static void Main()
{
string s = "中文 chinese";
Regex regx = new Regex("[\u4e00-\u9fa5]+");
Match m = regx.Match(s);
Console.WriteLine(m.Groups[0].Value); // 中文
Console.ReadKey();
}
}
匹配雙字節(jié)字符(包括漢字)
[^\x00-\xff]
[\u4e00-\u9fa5]
C#
復制代碼 代碼如下:
class Class1
{
static void Main()
{
string s = "中文 chinese";
Regex regx = new Regex("[\u4e00-\u9fa5]+");
Match m = regx.Match(s);
Console.WriteLine(m.Groups[0].Value); // 中文
Console.ReadKey();
}
}
匹配雙字節(jié)字符(包括漢字)
[^\x00-\xff]
相關(guān)文章
asp.net中利用正則表達式判斷一個字符串是否為數(shù)字的代碼
asp.net中利用正則表達式判斷一個字符串是否為數(shù)字的代碼,需要的朋友可以參考下。2011-12-12

