How to remove square brackets in string using regex?

前端 未结 4 1225
天涯浪人
天涯浪人 2020-11-29 08:47

[\'abc\',\'xyz\'] – this string I want turn into abc,xyz using regex in javascript. I want to replace both open close square bracket & single q

4条回答
  •  庸人自扰
    2020-11-29 09:28

    Use this regular expression to match square brackets or single quotes:

    /[\[\]']+/g
    

    Replace with the empty string.

    "['abc','xyz']".replace(/[\[\]']+/g,'')
    

提交回复
热议问题