Reputation: 6221
I am trying to do string.replace()
on the *
character. The string has multiple occurrences of the character and so I need to do a global replace, but if I do what seems natural it produces the comment tag.
x.replace(/*/g, '');
How do you work around this?
Upvotes: 0
Views: 58
Reputation: 28096
You'll need to escape the *
*
is a reserved lookup item:
*
Matches the preceding character 0 or more times. Equivalent to {0,}.For example, /bo*/ matches 'boooo' in "A ghost booooed" and 'b' in "A bird warbled", but nothing in "A goat grunted".
var jamie = '* 8 * *';
jamie = jamie.replace(/\*/g, '');
// 8
Upvotes: 3