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...
Is there an easy equivalent to this in JavaScript?  $find = array("<", ">", "\n"); $replace = array("&lt;", "&gt;", "<br/>");  $textarea = str_replace($find, $replace, $textarea);...
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");...
Goal:  Using jQuery, I'm trying to replace all the occurrences of:   <code> ... </code>   with:  <pre> ... </pre>   My solution:  I got as far as the following,   $('code').replaceWith( "<pre>" + $(...
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, '&...
I'd like to know how to replace a capture group with its uppercase in JavaScript. Here's a simplified version of what I've tried so far that's not working:  > a="foobar" 'foobar' > a.replace( /(f)/, "$1"...
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;...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.