['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 ""
.
views:
58answers:
3
+2
A:
Use this regular expression to match square brackets or single quotes:
/[\[\]']+/g
Replace with the empty string.
"['abc','xyz']".replace(/[\[\]']+/g,'')
Mark Byers
2010-09-28 11:07:21
thank you mark it is working
Mugdha
2010-09-28 11:22:54
+1
A:
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.
Greg Hewgill
2010-09-28 11:10:37
It's not JSON because JSON uses double quotes for strings, not single quotes. See: http://www.json.org/
Mark Byers
2010-09-28 11:12:48