Tarek Salah uddin Mahmud Tarek Salah uddin Mahmud - 1 year ago 124
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


I am not trying to replace all numbers.

I have to replace only
expression with

How do I do this in JavaScript?

Answer Source
var str = "abcd-123456.com"    
str = str.replace(/-[0-9]*/g, '')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download