Home >Web Front-end >JS Tutorial >The replace function replaces individual and global usage methods

The replace function replaces individual and global usage methods

一个新手
一个新手Original
2017-09-29 09:51:021778browse

//单个
var aa="1-2-3";
aa=aa.replace(',',".");
console.log(aa);

//Global replacement

var aa="1-2-3";
aa=aa.replace(/-/g,".");
console.log(aa);

##//Cut the content in the square bracket characters

var text ="hello [Word]";
var aaa=text.match(/([^\[\]]+)(?=\])/g)
console.log(aaa);

The above is the detailed content of The replace function replaces individual and global usage methods. 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