Skip to content Skip to sidebar Skip to footer

How To Negative Match Regex In Javascript String Replace?

I am trying to replace with a blank all characters except numbers, but this doesn't works: s.replace(/(?!\d)/g, '') Thanks!

Solution 1:

Use negative character classes:

s.replace(/[^0-9]+/g, '')

or s.replace(/[^\d]+/g, '')

or s.replace(/\D+/g, '')

Post a Comment for "How To Negative Match Regex In Javascript String Replace?"