Match and replace methods based on strings in JavaScript (detailed description), matchreplace

Source: Internet
Author: User

Match and replace methods based on strings in JavaScript (detailed description), matchreplace

1. match Method

The match () method can be used to search for a specified value in a string or to find a match between one or more regular expressions.

The Return Value of the match () method is an array of matching results.

2. replace Method

The replace () method is used to replace other characters with some characters in a string, or replace a substring that matches a regular expression.

The Return Value of the replace method is a new string.

3. Description

The parameters of the above two methods mainly add global g when using the regular expression, so that all strings can be matched or replaced.

Sample Code:

<! DOCTYPE html> 

Console output:

The above match and replace methods based on the strings in JavaScript (detailed description) are all the content shared by Alibaba Cloud xiaobian. I hope you can provide a reference and support for the customer's house.

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.