-1

How can I match the repetition of a character n times?

For example with this sample text

abcdddd123

123456777xssx

I want to match the three consecutive 7 and the three consecutive d

I've tried with

.{3}

But the quantifier {3}, as well as other quantifiers such as the asterisk, dones't seem to quantify the same character but any other different character as well.
I mean it doesn't repeat the first matched character muy the dot itself.
In my example it will match everything.

Community
  • 1
  • 1
skan
  • 7,423
  • 14
  • 59
  • 96
  • 1
    See: http://stackoverflow.com/questions/644714/what-regex-can-match-sequences-of-the-same-character – KernelPanic Mar 03 '17 at 20:02
  • 1
    `(.)\1{2}` = capture anything then use a backreference to it 2 more times. Result = same character 3 in a sequence. Some want quick eye recognition on the quantifier. For them, it would be `(?=(.))\1{3}` –  Mar 03 '17 at 21:16

1 Answers1

1

I think you need a group you can probably end up doing something like this to match any consecutive letter or number 3 times

([a-Z1-9])\1\1\1
johnny 5
  • 19,893
  • 50
  • 121
  • 195