C#正则表达式命名空间:using System.Text.RegularExpressions;
string s = "正则式,123,a11";
var match = Regex.Match(s, "^.{0,10}$");
if (match.Success)
{
Console.WriteLine("匹配成功");
}
else
{
Console.WriteLine("匹配失败");
}
.(点)表示匹配除了换行符之外的任意字符,{0,10}表示字符个数在0-10个