How to find the occurrences of the following characters in a string with a regular expression?

advertisements

How can I find occurences of same subsequent characters in a string with a regular expression or function?

Example:

I am l​ee​t and I have a thr​ee​ pi​zz​as. That n​oo​b right there has only one pi​zz​a. P​oo​r boy.


You can use a backreference:

/(.)\1/

Change \1 to \1+ if you want to find sequences of length two or more.

Note that the syntax can vary depending on the regular expression engine you are using.