Reputation: 19242
I have a string variable var str = 'this is eeeeeeee';
. I want to replace each letter e in this string. When I do str.replace('e', 'E');
it does it only to the first e
Upvotes: 1
Views: 163
Reputation: 207501
You need to use the global match g
with a regular expression
str.replace(/e/g, 'E');
Upvotes: 2
Reputation: 15599
You can use regular expressions to indicate you want to replace more than one instance. In this case you would use the g
flag.
'this is eeeeeeeee'.replace(/e/g, 'E')
More info can be found at replace - MDN
Upvotes: 6