The replace () method in JavaScript uses the details _ basics

Source: Internet
Author: User

This method finds a match between the strings of a regular expression and replaces the new substring of the matched substring.

The replacement string can contain the following special substitution modes:

Grammar

String.Replace (REGEXP/SUBSTR, newsubstr/function[, flags]);

The following are the details of the parameters:

    • RegExp: A RegExp object. Matches the return of the parameter being replaced.
    • SUBSTR: A string that is replaced by newsubstr
    • NEWSUBSTR: It replaces #1 of substrings received from parameters.
    • Functions: A function is called to create a new substring
    • Flags: Any combination string containing the regular expression flags: G-Global match, I-ignore case, M-matches multiple rows. This parameter is only used if the first parameter is a string.

return value:

    • It just returns a new change to the string

Example:

The following example shows how to use global and ignore case flags to allow substitution to use the string ' oranges ' instead of ' apples '

 
 


Example:

The following example shows how to convert a word in a string:

 
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.