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
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, ",");
Thank you so much.It worked
This topic is now closed. New replies are no longer allowed.