0

I'm trying to find a regex which finds 3 repeating characters appearing contiguously in a string. The character set could be alphabet, digit or any special character.

I wanted the first try for alphabet and digits and then extend the expression to include special characters. The ones I tried are. Both of these fail for the string "c2sssFg1". What am I doing wrong here?

(\\w*)\\2{3,}(\\w*)

(\\w*?)(\\w)\\2{3,}(\\w*)

I looked at some of the examples on SO and on web but I didn't find the right solution that passes the random strings I test. Can someone help me with this?

Thanks.

uncommon_breed
  • 172
  • 2
  • 2
  • 13

2 Answers2

6
(.)\1{2}

(.) matches any char

\1 matches that exactly char

{2} is to grant its 2 more of that

IWHKYB
  • 481
  • 3
  • 11
1

Try (.)\1\1. It works for general case.

NiVeR
  • 9,644
  • 4
  • 30
  • 35