且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

正则表达式检查一个字符的 3 个或更多连续出现

更新时间:2021-10-16 22:15:20

您可以使用正则表达式:

You can use the regex:

(?!.*(.)\1{2})^[a-zA-Z0-9.,()-]*$

它使用负前瞻(?!.*(.)\1{2}) 来确保没有任何字符的 3 组重复.

It uses the negative lookahead (?!.*(.)\1{2}) to ensure that there is no group of 3 repetitions of any of the characters.

然后它使用正则表达式 ^[a-zA-Z0-9.,()-]*$ 来确保字符串仅由字母、数字、句点、逗号、括号组成和连字符.

Then it uses the regex ^[a-zA-Z0-9.,()-]*$ to ensure that the string is made of just alphabets, numbers, period, comma, parenthesis and hyphen.

Rubular 链接