Regex To Match Consecutive Occurrences Of The Same Character In A String

A regular expression to match consecutive occurrences of the same character in a string. match a character that occurs x times (3 times in this regex) in a row in a string.

/([a-zA-Z0-9])\1{2}/

Matches:

  • Regggex
  • 2211122
  • Reggggex

Non-matches:

  • Reggex
  • 221122

See Also: