문제

http://jsperf.com/regex-not-word-selector

Why do /\W/g performs worse than /[^A-Za-z]/g?

Is it JS specific?

도움이 되었습니까?

해결책

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

\w is equivalent to [A-Za-z0-9_]

and

\^W is equivalent to [^A-Za-z0-9_]

Note that in implementations in other languages \w may or may not also match unicode characters.

The results are pretty close and in no way something I would worry about.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top