sajad torkamani


// Output: ['bbb', 'aaa', 'aaaa']


  • (\w): Match any alphanumeric character and store this in a capture group (think a temporary variable).
  • (\1+): match one or more characters that are the same as what was captured in the first capture group.

This example is written using String.match in JavaScript but the regex should be reusable across other languages. A Ruby example might look like:

# Output: ['bbb', 'aaa', 'aaaa']
Tagged: Regex

Leave a comment

Your email address will not be published. Required fields are marked *