I am trying to replace a character in a string with multiple occurences in Javascript.
String a1 = "There is a man over there";
when i use replace("e","x");
it will replace only the first occurrence of e.
So i am trying to use the g modifier like this replace(/e/g,"x");
But i am facing with this error Syntax error on tokens, Expression expected instead
I am not sure what i am doing wrong here.
replace(/e/g,"x")would be valid in JavaScript but not in Java. For Java just use the following: