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

javascript replace() regular replacement implementation code_javascript skills

WBOY
Release: 2016-05-16 18:33:56
Original
936 people have browsed it
Copy code The code is as follows:

var data = "123123,213,<,12312,> ,312,3,cat,dsfsdfs,";
alert(func(data));
function func(str)
{
var reg = /<|>/g;
str = str.replace(reg,function($1){
if($1=='<'){
return '<';
}else{
return '> ;';
}
});
return str;
}

It’s very basic...it’s best to draw inferences from one example.
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!