I have a string like %B~7566952
, and I want a regular expression that can be applied to replace it to get B7566952
, so a regular expression that takes non-alphanumeric characters and deletes them.
Asked
Active
Viewed 54 times
-2

meskobalazs
- 15,741
- 2
- 40
- 63

ncr07
- 57
- 1
- 7
-
The first paragraph of http://stackoverflow.com/a/9364527/2102532 does what you need, this should be closed as a duplicate. – meskobalazs Dec 29 '14 at 14:21
1 Answers
0
var str = "%B~7566952";
document.write(str.replace(/[^a-zA-Z0-9]/g, ""));

Sampath Liyanage
- 4,776
- 2
- 28
- 40
-
`str.replace(/\W/g, '')` is equivalent (well nearly, as the underscore character is in `W` but not in your expression) – meskobalazs Dec 29 '14 at 14:22