是否有定期的EX pression返回相同的字符重复的比赛? [英] Is there a regular expression to return a match of a repetition of the same characters?
问题描述
使用.NET正EX pressions。
Using .NET regular expressions.
让我们说我有以下文字:
Let's say I have the following text:
ddddddddddd
ddddddddddd
和我想测试超过2的重复的任意字符。
And I would like to test for a repetition of more than 2 for any character.
正则表达式不应返回匹配含双字母之类的词的文本的看的。
The regex should not return a match for a text containing double letters like the word "look".
不要假定输入文本只包含字母D的重复。 我想任何字符的重复。
Do not assume the input text only consists of repetition of the letter d. I want ANY repetition of characters.
推荐答案
试试这个
(.)\1{2,}
请参阅它这里Regexr
在。
匹配任何字符,这个字符存储,因为它周围的支架1组。该 \ 1 {2}
检查,然后进行2个或更多这个人物(与原来相匹配的字符,然后3个或更多在一起。)
The .
matches any character, this character is stored in group 1, because of the brackets around it. The \1{2,}
checks then for 2 or more of this character (together with the originally matched character then 3 or more.)
这篇关于是否有定期的EX pression返回相同的字符重复的比赛?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!