For example if I have a string:
I saw, I came, I conquer.
I want to replace all occurrences of “I” into “You”, which would yield this result.
You saw, You Came, You conquer.
My actual problem is that I have a link (anchor tag) which has an inner HTML of a string enclosed with a series of “ ”. I put that space to increase the clickable area of the link. Then I need to strip that spaces to get the exact value / content of the anchor tag.
When stripped, it should be: 1b
var text = //get the link inner HTML text = text.replace(/ /g, ""); alert(text);
The g parameter means global search. If not specified, only the first occurrence of the string is replace. To search all matching strings, use g parameter. To perform case-insensitive search, use i parameter.