Yahoo Web Search

Search results

  1. The meaning of REPLACE is to restore to a former place or position. How to use replace in a sentence. Synonym Discussion of Replace.

  2. to take the place of something, or to put something or someone in the place of something or someone else: The factory replaced most of its workers with robots. Tourism has replaced agriculture as the nation's main industry. B1. If you replace something broken, damaged, or lost, you provide a new one:

  3. to take the place of something, or to put something or someone in the place of something or someone else: The factory replaced most of its workers with robots. Tourism has replaced agriculture as the nation's main industry. B1. If you replace something broken, damaged, or lost, you provide a new one:

    • Overview
    • Syntax
    • Description
    • Examples
    • Browser compatibility
    • See also

    The replace() method of String values returns a new string with one, some, or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function called for each match. If pattern is a string, only the first occurrence will be replaced. The original string is left unchanged.

    Parameters

    pattern Can be a string or an object with a Symbol.replace method — the typical example being a regular expression. Any value that doesn't have the Symbol.replace method will be coerced to a string. replacement Can be a string or a function. •If it's a string, it will replace the substring matched by pattern. A number of special replacement patterns are supported; see the Specifying a string as the replacement section below. •If it's a function, it will be invoked for every match and its return value is used as the replacement text. The arguments supplied to this function are described in the Specifying a function as the replacement section below.

    Return value

    A new string, with one, some, or all matches of the pattern replaced by the specified replacement.

    This method does not mutate the string value it's called on. It returns a new string.

    A string pattern will only be replaced once. To perform a global search and replace, use a regular expression with the g flag, or use replaceAll() instead.

    If pattern is an object with a Symbol.replace method (including RegExp objects), that method is called with the target string and replacement as arguments. Its return value becomes the return value of replace(). In this case the behavior of replace() is entirely encoded by the @@replace method — for example, any mention of "capturing groups" in the description below is actually functionality provided by RegExp.prototype[@@replace].

    If the pattern is an empty string, the replacement is prepended to the start of the string.

    Defining the regular expression in replace()

    In the following example, the regular expression is defined in replace() and includes the ignore case flag. This logs 'Twas the night before Christmas...'.

    Using the global and ignoreCase flags with replace()

    Global replace can only be done with a regular expression. In the following example, the regular expression includes the global and ignore case flags which permits replace() to replace each occurrence of 'apples' in the string with 'oranges'. This logs 'oranges are round, and oranges are juicy'.

    Switching words in a string

    The following script switches the words in the string. For the replacement text, the script uses capturing groups and the $1 and $2 replacement patterns. This logs 'Cruz, Maria'.

    BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

    •Polyfill of String.prototype.replace in core-js with fixes and implementation of modern behavior like Symbol.replace support

    •String.prototype.replaceAll()

    •String.prototype.match()

    •RegExp.prototype.exec()

    •RegExp.prototype.test()

    •Symbol.replace

    Code sample

    var str = 'Twas the night before Xmas...';
    var newstr = str.replace(/xmas/i, 'Christmas');
    console.log(newstr); // Twas the night before Christmas
  4. Replace definition: to assume the former role, position, or function of; substitute for (a person or thing). See examples of REPLACE used in a sentence.

  5. Feb 26, 2012 · You can use str.replace () as a chain of str.replace (). Think you have a string like 'Testing PRI/Sec (#434242332;PP:432:133423846,335)' and you want to replace all the '#',':',';','/' sign with '-'. You can replace it either this way (normal way), >>> string = 'Testing PRI/Sec (#434242332;PP:432:133423846,335)'.

  6. People also ask

  1. People also search for