36 ms·
> [-\.\\w] means match a dash, a dot, a backslash and the w character. That one could very well depend on language: <?php var_dump(preg_match('/[\\w]/', '
by sapphirecat 18y ago
> [-\.\\w] means match a dash, a dot, a backslash and the w character.
That one could very well depend on language:
<?php var_dump(preg_match('/[\\w]/', 'Lies.')); ?>
int(1)
Note that PHP still interprets \' and \\ in single-quotes, too.
- thwarted 18y agoWell, sure, but when you're talking about regular expressions and don't give them a context (which you did in your PHP example above), you should be using regular expression escaping syntax, not one that is based on a context that isn't mentioned. PCRE are the same no matter which language or application uses the library, how the language serializes and represents regular expression literals is an aspect of the language, not of the regular expression engine. Oddly, it's really unintuitive to specify a character class as you have above that is composed of the backslash and the w character in PHP. The PHP single quoted string '\\w' and '\w' are exactly the same, and end up being the same to the regular expression engine. If you want to put a backslash in your regular expression, you need to quadruple it.