I'm trying to replace multiple words in a string with multiple other words. The string is "I have a cat, a dog, and a goat."  However, this does not produce "I have a dog, a goat, and a cat", but instead it produces "I have...
I have a string, let's say Hello world and I need to replace the char at index 3. How can I replace a char by specifying a index?  var str = "hello world";   I need something like  str.replaceAt(0,"h");...
I need to remove all JavaScript comments from a JavaScript source using the JavaScript RegExp object.  What I need is the pattern for the RegExp.  So far, I've found this:  compressed = compressed.replace(/\/\*.+?\*\/|\/\/.*(?=[\n\r])/g, '&...
Using jQuery, I'd like to remove the whitespace and line breaks between HTML tags.  var widgetHTML = '    <div id="widget">        <h2>Widget</h2><p>Hi.</p>        </div>';   Should be:  alert...
I need to highlight, case insensitively, given keywords in a JavaScript string.  For example:   highlight("foobar Foo bar FOO", "foo") should return "<b>foo</b>bar <b>Foo</b> bar <b>FOO</b>...
I am so close to getting this, but it just isn't right.  All I would like to do is remove the character r from a string.  The problem is, there is more than one instance of r in the string. However, it is always the character at index 4 (so the...
Given this function:  function Repeater(template) {      var repeater = {          markup: template,          replace: function(pattern, value) {             this.markup = this.markup.replace(pattern, value);         }      };      return repeater;...
I have this string:  "Test abc test test abc test test test abc test test abc"   Doing:  str = str.replace('abc', '');   seems to only remove the first occurrence of abc in the string above.  How can I replace all occurrences...
For some reason the "".replace() method only replaces the first occurrence and not the others. Any ideas?...
This question already has answers here:...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.