问题
I am trying to replace with a blank all characters except numbers, but this doesn't works:
s.replace(/(?!\d)/g, '')
Thanks!
回答1:
Use negative character classes:
s.replace(/[^0-9]+/g, '')
or s.replace(/[^\d]+/g, '')
or s.replace(/\D+/g, '')
来源:https://stackoverflow.com/questions/24419609/how-to-negative-match-regex-in-javascript-string-replace