Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a regular expression to return a match of a repetition of the same characters?

Tags:

.net

regex

Using .NET regular expressions.

Let's say I have the following text:

ddddddddddd

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".


UPDATE

Do not assume the input text only consists of repetition of the letter d. I want ANY repetition of characters.

like image 302
Stécy Avatar asked Nov 28 '25 13:11

Stécy


1 Answers

Try this

(.)\1{2,}

See it here on Regexr

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.)

like image 106
stema Avatar answered Nov 30 '25 04:11

stema



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!