Reputation: 11764
Are there differences between these two?
replace(/[^a-z0-9]/gi, '');
replace(/[^a-zA-Z0-9]/g, '');
Also, are there any significant differences in time using one or another?
edit: about the performance, I did some testing http://jsperf.com/myregexp-test
Upvotes: 8
Views: 21296
Reputation: 35294
Nope, by the first, the i
at the end makes the regex case insensitive meaning that it doesn't matter if the letter it finds is upper- or lower-case.
The second matches upper- and lower-case letters but makes sure they are either upper- or lower-case. So you end up with the same result.
Upvotes: 6