如何用正则表达式匹配长尾词中的中文和双字节字符?
- 内容介绍
- 文章标签
- 相关推荐
本文共计90个文字,预计阅读时间需要1分钟。
适配中文字符+[\u4e00-\u9fa5]+
[\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();
}
}
匹配双字节字符(包括汉字)
[^\x00-\xff]
本文共计90个文字,预计阅读时间需要1分钟。
适配中文字符+[\u4e00-\u9fa5]+
[\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();
}
}
匹配双字节字符(包括汉字)
[^\x00-\xff]

