Home > Web Front-end > JS Tutorial > Introduction to the use of replace method in js_javascript skills

Introduction to the use of replace method in js_javascript skills

WBOY
Release: 2016-05-16 17:18:33
Original
1070 people have browsed it

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

It should be noted that: If regexp has the global flag g when replacing with a regular expression, then the replace() method will replace all matching substrings. Otherwise, it only replaces the first matching substring.

The following is a simple example:

Copy the code The code is as follows:


//As a result, it only replaces the first letter. But if you add a regular expression, the result will be different! replace() supports regular expressions, it can match characters or strings according to the rules of regular expressions, and then replace them!

//But the result is still unchanged, it will be OK with a little modification.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template