I’m trying to add the character Ö (U+00D6) to my regular expression below. Apparently something is going wrong because it’s not working on my preg_match function.
The regular expression that works fine:
/^([A-Z]{1})[a-z]{1,31}$/
The one that should work but does not:
/^([A-Z\x{00D6}]{1})[a-z]{1,31}$/
I’m obviously trying to create a regular expression that is started with an uppercase letter extended with Ö and followed by lowercase letters. In total, the length of the string must be between 2-32. What is wrong with the regular expression that contains the Unicode expression for Ö?
The
\x{00D6}will only match the single byte\xD6symbol. When you pass in a string topreg_matchit’s however most likely encoded in UTF-8, which is\xC3 \x96.You need to use the
/umodifier for your regex to support that.Also the
{1}is decorative, but redundant.