Domanda

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

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

Is it JS specific?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top