111,126
社区成员
发帖
与我相关
我的任务
分享regex=/^(?:([0-9])(?!\1{5})){12}$/;
^(?:([0-9])(?!\1{5})){12}$
//看比较复杂的正则从内到外看
^$之间的正则表示只匹配正则的内容
([0-9])//捕获数字的一个组
([0-9])(?!\1{5}) \1表示的值是这个组所匹配的数字 {5}即连续5次,加上原本的一次所以一共6次
表达式(?!表达式)的意思是表达式后面不跟某个表达式
由于内部匹配的数字 这里的12表示是一共12个数字。
解释正则是比较累的。。。。。。 Hate It
\b\b和^$是一样的,习惯写法 一般用^$ 原因,我喜欢!!!
\b(?:([0-9])(?!\1{5})){12}\b^(?:([0-9])(?!\1{5})){12}$using System;
using System.IO;
using System.Text.RegularExpressions;
namespace CSDN
{
class Application
{
static void Main()
{
bool b = Check("123456789012");
b = Check("123333334567");
}
static bool Check(string s)
{
if (Regex.Match(s, "^\\d{1,12}$").Success)
{
return !(Regex.Match(s, @"(\d)\1{5}").Success);
}
return false;
}
}
}