Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
159
rated 0 times [  162] [ 3]  / answers: 1 / hits: 17772  / 13 Years ago, sun, september 4, 2011, 12:00:00

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


More From » regex

 Answers
3

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.


[#90278] Thursday, September 1, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ishmaelw

Total Points: 528
Total Questions: 96
Total Answers: 103

Location: Venezuela
Member since Sat, Apr 24, 2021
3 Years ago
;