Regex To Match Characters Repeated More Than A Specified Number Of Times

A regular expression that characters repeated more than a specified number of times (9 times in this example).

This can be useful in finding the duplicate characters in a string.

/(.)\1{9,}/

Explain:

  • () Capturing group #1. Groups multiple tokens together and creates a capture group for extracting a substring or using a backreference.
    • . Dot. Matches any character except line breaks.
  • \1 Numeric reference. Matches the results of capture group #1.
  • {9,} Quantifier. Match 9 or more of the preceding token.

Matches:

  • aaaaaaaaaa
  • aaaaaaaaaaa
  • ==========-

Non-matches:

  • aaa
  • ababababab

See Also: