正则表达式基本语法元字符

\d  匹配数字 0-9 

代码示例

string s = Console.ReadLine();
string pattern = @"^\d*$";
//\d 代表0-9的数字 ^表示以数字开头 $表示以数字结尾。*表示0~n个字符。
bool isMatch = Regex.IsMatch(s, pattern);

Console.WriteLine(isMatch);
Console.ReadKey();

猜你喜欢

转载自www.cnblogs.com/zyfadmin/p/8970197.html