自定义去除字符

最后更新于:2022-04-02 03:23:58

[TOC] ### 自定义去除字符 ``` String.prototype.OkTrim=function (tag) { var notreg = '^\\/()'; if (notreg.indexOf(tag)!=-1){ tag = '\\'+tag; } var reg =new RegExp('^'+tag+'|'+tag+'$','g'); return this.replace(reg,''); } '^asdasd^'.OkTrim('^'); //asdasd "hello word he".OkTrim('he'); //llo word ```
';