4

I am trying to replace with a blank all characters except numbers, but this doesn't works:

s.replace(/(?!\d)/g, '')

Thanks!

1

1 Answer 1

12

Use negative character classes:

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

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

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

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.