RegEx to find two or more consecutive chars

This should do the trick:

[a-zA-Z]{2,}

[a-zA-Z]{2,} does not work for two or more identical consecutive characters. To do that, you should capture any character and then repeat the capture like this:

(.)\1

The parenthesis captures the . which represents any character and \1 is the result of the capture - basically looking for a consecutive repeat of that character. If you wish to be specific on what characters you wish to find are identical consecutive, just replace the "any character" with a character class...

([a-zA-Z])\1

Finds a consecutive repeating lower or upper case letter. Matches on abbc123 and not abc1223. To allow for a space between them (i.e. a ab), then include an optional space in the regex between the captured character and the repeat...

([a-z]A-Z])\s?\1

Personally I've used:

[0-9][0-9]+.

But the answer from Simon, is way better.

Tags:

Regex