[Javascript] How to strip all numeric characters from a string?


I want to strip all the numeric characters from a given string, How can I do that in JavaScript

1 Answer

3 years ago by

Use regex to remove all the alphabets from a given string as shown below

let str = "This is a test message with id 12345";


// to remove all the alphabets
console.log(str.replace(/[A-Za-z\s+]/g, '')) // Outputs "12345"

// to remove all the numbers
console.log(str.replace(/\d/g, '')) // Outputs "This is a test message with id"

Run here https://onecompiler.com/javascript/3xns3vzfb

3 years ago by Meera