Remove all characters but digits from string – JavaScript

The following regular expression will match for a single character not present in the range between 0 (ASCII 48) and 9 (ASCII 57) (case sensitive).

Meaning it will convert from Test123 to Test.

myString = myString.replace(/[^0-9]/g, '');
Code language: JavaScript (javascript)

Reading material

About Ricard Torres

Senior Front-end Software Engineer at Netcentric, from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

@ricard_dev @ricard_dev

📝 Blog 🎙 Podcast

One comment

Leave a Reply

Add <code> Some Code </code> if you need to.