简体   繁体   中英

JavaScript code to remove the special characters []{}<>

Could any one suggest code to remove mentioned special characters: []{}<>

Code inside the JavaScript tags:

var name="formattting[]{}<>";

rename = name.replace(/[<{>}([)]/g,"");

Output:

formattting]

Here out of six special symbols, five symbols are removed and now my concern is to remove the special character ] .

尝试这个:

rename = name.replace(/[[\]{}<>]/g, "");

You need to escape special characters in regex:

var name="formattting[]{}<>";
rename = name.replace(/[\$<{>}9\(\[\)\]]/g,"");
alert(rename)

Simply escape the \\]

var name="formattting[]{}<>";
var rename = name.replace(/[<{>}([)\]]/g,"");

alert(rename);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM