ksd07 — 2014-03-11T08:55:36-04:00 — #1
I will get the data from the server as NY^NJ^CA^MI or NC^SC etc and need to replace "^" with "," (coma) . I have tried following two approaches but not working.
Can anyone guide me what went wrong with these approaches?
Ex: var str="NY^NJ^CA^MI";
var test = str.replace(/^/g, ",");
var test = str.replace(/^/g, ',');
Thanks in advance
pullo — 2014-03-11T10:34:31-04:00 — #2
The problem, is that the caret (^) is a special character in regular expressions which normally represents the start of the current line.
You will need to escape it if you want to match a normal caret:
var test = str.replace(/\\^/g, ",");
ksd07 — 2014-03-12T23:36:44-04:00 — #3
Thank you so much.It worked