正则表达式=》判断中文字

判断中文字

csharp 复制代码
//Name Classification
string input = "Eng中";
string patternZh = @"^\(*([\u4E00-\u9FFF'_\s\.\,\-]{1,98})?\)*$";
Match match = Regex.Match(input, patternZh);
Console.WriteLine("測試:"+input);
if (match.Success ==true)
{
    Console.WriteLine("True=>Chinese Word Only");
}else
{
    Console.WriteLine("False");
}

input = "Angela";
match = Regex.Match(input, patternZh);
Console.WriteLine("測試:" + input);
if (match.Success == true)
{
    Console.WriteLine("True=>Chinese Word Only");
}
else
{
    Console.WriteLine("False");
}

input = "中文名";
match = Regex.Match(input, patternZh);
Console.WriteLine("測試:" + input);
if (match.Success == true)
{
    Console.WriteLine("True=>Chinese Word Only");
}
else
{
    Console.WriteLine("False");
}
相关推荐
「QT(C++)开发工程师」5 小时前
C++ 11 常用for循环
开发语言·c++
我还记得那天5 小时前
0 初识C++
开发语言·c++
FfHUCisI5 小时前
Go 编译过程全景
开发语言·后端·golang
FfHUCisI5 小时前
Golang 语法分析与 AST:Parser 与 go/ast
开发语言·后端·golang
lemon_sjdk6 小时前
ObjectProperty
java·开发语言·算法
大模型码小白6 小时前
Spring AI Tool 实现自然语言操作 MySQL 数据库详解
服务器·开发语言·数据库·人工智能·python·mysql·spring
hh9506 小时前
Agent Plan x DeepSeek Harness:Agent 供应链安全与第三方插件审计
java·开发语言·安全·agent plan·adg成都社区·adg社区
Behaviour7 小时前
Unity UI循环列表UIScrollViewContent实现
ui·unity·c#·游戏引擎
「QT(C++)开发工程师」7 小时前
C++ std::move 详解
开发语言·c++