Multiple Regex replace

后端 未结 5 680
一生所求
一生所求 2021-01-17 11:24

I am boggled by regex I think I\'m dyslexic when it comes to these horrible bits of code.. anyway, there must be an easier way to do this- (ie. list a set of replace instanc

5条回答
  •  梦毁少年i
    2021-01-17 11:45

    You can just chain them all in order.

    function clean(string) {
        return string.replace(/\@~rb~@/g, '').replace(/}/g, '@~rb~@')
                     .replace(/\@~lb~@/g, '').replace(/{/g, '@~lb~@')
                     .replace(/\@~qu~@/g, '').replace(/\"/g, '@~qu~@')
                     .replace(/\@~cn~@/g, '').replace(/\:/g, '@~cn~@')
                     .replace(/\@-cm-@/g, '').replace(/\,/g, '@-cm-@');
    }
    

提交回复
热议问题