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.