user2644549
user2644549

Reputation: 141

How to replace all * characters in a string using a regular expression

I want to delete * characters if it is present in a string.

This is my code but it's not working.

String.replace(/*/g '')

Upvotes: 2

Views: 76

Answers (2)

BlackWhite
BlackWhite

Reputation: 832

"Your string".replace("*", ""); 

Upvotes: 1

iPao
iPao

Reputation: 1163

You have to escape the special character * with a backslash, as it has another meaning in a regex.

String.replace(/\*/g, '');

Upvotes: 5

Related Questions