-1

I have this sorta string = "^My Name Is Robert.^" I want to remove the occurrences of ^ from this string. I tried the replace method like :

replyText.replace(/^/g, '');

But it hasn't any affect. Using the replace without the global works but only removes the first occurrence.

Should I just make a loop and keep looping the string with replace till no more '^' are contained, or is there a better way?

Giannis
  • 1,790
  • 1
  • 11
  • 29
Clueless
  • 109
  • 10

2 Answers2

3

You need to escape the ^ character in RegEx:

replyText.replace(/\^/g, '');
Dom
  • 734
  • 3
  • 8
0

The caret, ^, is a special character in Regex, therefore it has to be escaped with a backslash i.e

replyText.replace(/\^/g, '')