Hi I have a variable in a Silex route and we only allow alphanumeric values
->assert('hash','\w+') I would like to also allow a dot in the variable, but my efforts at editing this regex have failed. Help greatly appreciated, thanks!
Try
->assert('hash', '[a-zA-Z0-9.]+') Why not [\w.]?
You tagged your question as PHP so I assume that this manual applies. And there it reads
\w any "word" character
and
A "word" character is any letter or digit or the underscore character, that is, any character which can be part of a Perl "word". The definition of letters and digits is controlled by PCRE's character tables, and may vary if locale-specific matching is taking place. For example, in the "fr" (French) locale, some character codes greater than 128 are used for accented letters, and these are matched by \w.
So after all \w might match äöüß... you don't know.
As it reads hash you may also want to try
->assert('hash', '[a-fA-F0-9.]+') which only accepts hex-digits and . and not G or Z or ...
A 'word' character is any letter or digit or the underscore character. The definition of letters and digits may vary if locale-specific matching is taking place. For example, in the "fr" (French) locale, some character codes greater than 128 are used for accented letters, and these are matched by \w.utf8" pragma, identifiers may contain any character that matches \w, even if it's in the >127 range.\w varies with locale and matche more than [a-zA-Z] and less than [^ ] ;-)
\wincludes underscore. And, that its meaning changes if your RE engine is set for Unicode semantics.