Home  >  Article  >  Web Front-end  >  About advanced replacement of javascript regular expressions

About advanced replacement of javascript regular expressions

零到壹度
零到壹度Original
2018-03-19 14:18:571948browse

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!

Statement:
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