JavaScript JS - Regex Replace Duplicate Letters regex replace duplicate words,regex replace duplicate characters,regex replace

So I have these strings:

  • Balloon
  • DDuupplliiccaattee
  • Noodle

I know how to replace all duplicate characters, but that's not what I'm after. I don't want Balloon to become Balon, for example. I only want to replace if the full string is a duplicate, such as DDuupplliiccaattee becoming Duplicate... Keeping Balloon and Noodle as they are.

Any ideas?

Answer:1

I think you are probably looking for something like this:

/\b((.)\2)+\b/

Breakdown:

\b - matches start word boundary

((.)\2)+ - match 1 or more groups of duplicate characters

\b - matches end word boundary

Answer:2

I have problem with AJAX and database. I don't know what I have now to do. So, I have this AJAX code: <script> function showCity(str) { if (str == "") { document.getElementById("...

I have problem with AJAX and database. I don't know what I have now to do. So, I have this AJAX code: <script> function showCity(str) { if (str == "") { document.getElementById("...

  1. show results in english
  2. show results for lotto
  3. show results for
  4. show results in powershell
  5. show results for powerball
  6. results show dancing with the stars

This should be simple but I guess no jQuery makes it a bit difficult. I want to repeat a process where a div goes 100px to the right (with animation) and then 100px to the left (so i want a continuous ...

This should be simple but I guess no jQuery makes it a bit difficult. I want to repeat a process where a div goes 100px to the right (with animation) and then 100px to the left (so i want a continuous ...

  1. make a left and then a right

I have used Dylan's question on here regarding JavaScript syllable counting, and more specifically artfulhacker's answer, in my own code and, regardless of which single or multi word string I feed it, ...

I have used Dylan's question on here regarding JavaScript syllable counting, and more specifically artfulhacker's answer, in my own code and, regardless of which single or multi word string I feed it, ...

I am doing image editing integration with Aviary. Below is the html code <body> <a href="#" onclick="return launchEditor('editableimage1','http://www.html5canvastutorials.com/demos/assets/...

I am doing image editing integration with Aviary. Below is the html code <body> <a href="#" onclick="return launchEditor('editableimage1','http://www.html5canvastutorials.com/demos/assets/...