Home > Web Front-end > JS Tutorial > body text

About advanced replacement of javascript regular expressions

零到壹度
Release: 2018-03-19 14:18:57
Original
1926 people have browsed it

This time I will bring you the advanced replacement method of JavaScript regular expressions. The following is a case, follow the editor to take a look.

Ordinary regular replacement generally replaces the first matched value or all matched values ​​replaces ,

For example:

"abc,abc,ab".replace(/a/,'1');

Result: "1bc,abc,ab";

##"abc,abc,ab".replace(/a/g ,'1');

Result: "1bc,1bc,1b"

Advanced point Replacement: Replace the third digit of the IP address with *.

192.168.33.12 becomes 192.168.*.12

##"192.168.33.12".replace (/(\d{1,3}).(\d{1,3}).(\d{1,3}).(\d{1,3})/,"$1.$2.*. $4")

The above is the detailed content of About advanced replacement of javascript regular expressions. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!