Regex to remove duplicate letters but not numbers -


what appropriate regex remove adjacent duplicate letters not numbers?

for example:

p11ppppl  --> p11pl 

i had following regex:

 /[^\w\s]|(.)(?=\1)/g 

but replaces duplicate numbers.

i (visualized here):

/([a-za-z])(?=\1)/g 

here's example in python:

in [21]: re.sub(r'([a-za-z])(?=\1)', '', 'p11ppppl') out[21]: 'p11pl' 

you use:

/([\d])(?=\1)/g 

for except digits, or:

/([\w])(?=\1)/g 

for "word characters".

as @casimir et hippolyte mentioned in comments, can use:

/([a-za-z])\1+/g 

with \1 replacement string, may better approach.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo