Skip to content
Advertisement

Lookahead and Lookbehind validation for each letters in a string (Regular Expression XYX or XXX matching) [closed]

I need to find the letters which have the same letter before and after. Using regular expression how do that?

Example:

JavaScript

Basically, I need to find out pattern XXX or XYX, excluding special characters or space.

Advertisement

Answer

Here’s a solution using JavaScript with regex:

JavaScript

The results are stored in group 1.

JavaScript

Not sure where does ele come from same letter / triple letters and ssss from princessship / mistressship. I assume those are typos

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement