Search code examples
javascriptregexwhitespace

JavaScript regex whitespace characters


I have done some searching, but I couldn't find a definitive list of whitespace characters included in the \s in JavaScript's regex.

I know that I can rely on space, line feed, carriage return, and tab as being whitespace, but I thought that since JavaScript was traditionally only for the browser, maybe URL encoded whitespace and things like   and %20 would be supported as well.

What exactly is considered by JavaScript's regex compiler? If there are differences between browsers, I only really care about webkit browsers, but it would be nice to know of any differences. Also, what about Node.js?


Solution

  • HTML != Javascript. Javascript is completely literal, %20 is %20 and   is a string of characters & n b s p and ;. For character classes I consider nearly every that is RegEx in perl to be applicable in JS (you can't do named groups etc).

    http://www.regular-expressions.info/javascript.html is the refernece I use.