About 133,000 results
Open links in new tab
  1. javascript - How do I replace all occurrences of a string ... - Stack ...

    Given a string: string = "Test abc test test abc test test test abc test test abc"; This seems to only remove the first occurrence of abc in the string above: string = string.replace('ab...

  2. string - How to replace several words in javascript - Stack Overflow

    I wanna replace several words in a text using replace() in javascript, how can I do that? For example, if I wanna replace, 'Dave Chambers, David Chambers, Will Smith' with 'Jackie Chan', no matter if they're in upper-case or lower-case, do I have to keep repeating the replace() method on the same string variable everytime, i.e.

  3. javascript - Replace multiple characters in one replace call - Stack ...

    Feb 18, 2022 · You could also try this : function replaceStr(str, find, replace) { for (var i = 0; i < find.length; i++) { str = str.replace(new RegExp(find[i], 'gi'), replace[i ...

  4. javascript - Replace multiple strings with multiple other strings ...

    It will replace all instances of the parameters, no matter how many times they are referenced: String.prototype.fmt = function (hash) { var string = this, key; for (key in hash) string = string.replace(new RegExp('\\{' + key + '\\}', 'gm'), hash[key]); return string } You would invoke it …

  5. How can I replace specific word combinations in a string in …

    Jan 19, 2021 · You can use the replace() method to replace all occurrences of a word or substring inside another string. Let's check out the code : <script> var myStr = "the Lord of the Rings"; var newStr = myStr.replace(/the Lord of the Rings/g, "LotR"); // Printing the modified string document.write(newStr); </script>

  6. javascript - Replace words in the body text - Stack Overflow

    May 5, 2017 · To replace all instances of the target string, use a simple regular expression with the global flag: document.body.innerHTML = document.body.innerHTML.replace(/hello/g, 'hi'); Share

  7. How do I replace a character at a specific index in JavaScript?

    METHOD1: split the string using two substrings and stuff the character between them; METHOD2: convert the string to character array, replace one array member and join it; Personally, I would use these two methods in different cases. Let me explain.

  8. Javascript: regex for replace words inside text and not part of the ...

    A word boundary is defined as a position where a word character follows a non-word character, or vice versa. A word character is defined as [a-zA-Z0-9_] in JavaScript. Start-of-string and end-of-string positions can be word boundaries as well, as long as they are followed or preceded by a word character, respectively.

  9. javascript - Replacing the last word in a string - Stack Overflow

    Aug 26, 2015 · To get around this issue i am using javascript to replace the value, for example: value = value.replace("St", "Street"); However if i then have, for example, a value that is 'Stanley Street' it would return 'Streetanley Street'. Does anybody know of a method i can use to apply the replace method to the last word in a string?

  10. javascript - Replacing only whole word, not words - Stack Overflow

    Dec 15, 2014 · I am trying to replace whole words only, but my script replaces all the case-sensitive instances of the word. Here is my code: &lt;script&gt; function repl() { var lyrics = document.getElementBy.

Refresh