正則表達式匹配中文與雙字節(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#
復(fù)制代碼 代碼如下:
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)文章
php正則之函數(shù) preg_replace()參數(shù)說明
php正則之函數(shù) preg_replace()參數(shù)說明...2007-03-03
javascript正則表達式處理中文和中文標(biāo)點符號的過程
在寫項目時遇到需要匹配字符串中所有的漢字并且包括簡單的中文標(biāo)點符號,下面這篇文章主要給大家介紹了關(guān)于javascript正則表達式處理中文和中文標(biāo)點符號的相關(guān)資料,需要的朋友可以參考下2024-02-02

