110,536
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Text.RegularExpressions;
class MainClass
{
static void Main()
{
string s="12_45A67921";
s = Regex.Match(s, @"^(([a-zA-Z])|[0-9_]){6,16}(?(2)$|^)").Value;
Console.WriteLine(s);
Console.Read();
}
}
//
// 更改构造 (?(2)$|^) 的意思是:
// 如果 2 组(内层括号)有捕获,就与 $ 匹配,
// 否则与 ^ 匹配,人为造成匹配失败。