我需要一个验证的表达式,如下所示:
1234-567.890-123
我的解决方案[0-9]{13,}[-\.]{0,3}
无法正常工作,因为这只会验证:
1234567890123 .-。
答案 0 :(得分:1)
如果字符串中的字符排序无关紧要,可以使用
^(?=(?:[\d.-]){13,}$)(?=(?:\D*\d){13,})(?!(?:[^.-]*[.-]){4}).*$
正则表达式细分
^ #Starting of string
(?=(?:[\d.-]){13,}$) #Lookahead which sees that the string only contains digits, . and -
(?=(?:\D*\d){13,}) #Lookahead to match 13 digits
(?!(?:[^.-]*[.-]){4}) #Looahead so that the number of . and - are not equal to 4
.*
$
中间部分
(?= #Lookahead
(?:\D*\d) #Match all non-digits and then digit.
{13,} #Repeat this at least 13 times.In simple words, it is matching at least 13 digits.
)