" with "<>" instances in one go"/> " with "<>" instances in one go">

Home  >  Article  >  Web Front-end  >  javascript replace() regular replacement implementation code_javascript skills

javascript replace() regular replacement implementation code_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:33:56961browse
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.
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