What is the appropriate regex to remove adjacent duplicate letters but not numbers?
For example:
p11ppppl --> p11pl
I had the f
I would do it like this (visualized here):
/([a-zA-Z])(?=\1)/g
Here's an example in Python:
In [21]: re.sub(r'([a-zA-Z])(?=\1)', '', 'p11ppppl')
Out[21]: 'p11pl'
You could also use:
/([\D])(?=\1)/g
for everything except digits, or:
/([\w])(?=\1)/g
for all "word characters".
As @Casimir et Hippolyte mentioned in the comments, we can also use:
/([a-zA-Z])\1+/g
with \1
as the replacement string, which may be a better approach.