如何使用正则表达式删除字符串中的方括号? [英] How to remove square brackets in string using regex?

查看:436
本文介绍了如何使用正则表达式删除字符串中的方括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

['abc','xyz'] - 这个字符串我想转成 abc,xyz 使用正则表达式在javascript中。我想要更换两个开放式方形支架和带有空字符串的单引号,即

['abc','xyz'] – this string I want turn into abc,xyz using regex in javascript. I want to replace both open close square bracket & single quote with empty string ie "".

推荐答案

使用此常规表达式匹配方括号或单引号:

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

/[\[\]']+/g

替换为空字符串。

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

这篇关于如何使用正则表达式删除字符串中的方括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆