pillarjs / path-to-regexp

Turn a path string such as `/user/:name` into a regular expression

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When parsed to tokens, why are backslashes stripped from pattern?

Lord-Kamina opened this issue · comments

When creating tokens out of a match, why does the lexer function skip \ inside patterns? (For example, turning \w+ into just w+?

It's not the lexer, it is javascript. See what the output is of console.log('\w+').

Tip: Backslashes need to be escaped with another backslash in JavaScript strings.

It's not the lexer, it is javascript. See what the output is of console.log('\w+').

Tip: Backslashes need to be escaped with another backslash in JavaScript strings.

Ah, makes sense. I didn't account for that, as I got here from a C++ port, with which we generally use raw strings. :P

Thanks for the quick reply!