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

判断中文字

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");
}
相关推荐
清水白石0081 分钟前
Python 编程实战全景:从基础语法到插件架构、异步性能与工程最佳实践
开发语言·python·架构
Halo_tjn2 小时前
Java 基于字符串相关知识点
java·开发语言·算法
梦想的颜色2 小时前
java 利用redis来限制用户频繁点击
java·开发语言
报错小能手2 小时前
Swift 并发 Combine响应式框架
开发语言·ios·swift
万法若空3 小时前
C++ <memory> 库全方位详解
开发语言·c++
代码中介商3 小时前
C++ 类型转换深度解析:static_cast、dynamic_cast、const_cast、reinterpret_cast
开发语言·c++
青小莫3 小时前
C++之string(OJ练习)
开发语言·c++·stl
freshman_y3 小时前
一篇介绍C语言中二级指针和二维数组的文章
c语言·开发语言
-Marks-3 小时前
【C++编程】STL简介 --- (是什么 | 版本发展历程 | 六大组件 | 重要性缺陷以及如何学习)
开发语言·c++·学习·stl·stl版本