Tarek Salah uddin Mahmud Tarek Salah uddin Mahmud - 1 month ago 7
Javascript Question

Replace an expression in string using javascript

I have a string that has some numbers in the middle of the string.

For example,

var str = "abcd-123456.com"


I want to remove the numbers like this

abcd.com


I am not trying to replace all numbers.

I have to replace only
-*.
expression with
""
.

How do I do this in JavaScript?

Answer
var str = "abcd-123456.com"    
str = str.replace(/-[0-9]*/g, '')