How to remove square brackets in string using regex?

前端 未结 4 1237
天涯浪人
天涯浪人 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:31

    You probably don't even need string substitution for that. If your original string is JSON, try:

    js> a="['abc','xyz']"
    ['abc','xyz']
    js> eval(a).join(",")
    abc,xyz
    

    Be careful with eval, of course.

提交回复
热议问题