php regex word boundary matching in utf-8

后端 未结 4 977
半阙折子戏
半阙折子戏 2020-11-27 08:30

I have the following php code in a utf-8 php file:

var_dump(setlocale(LC_CTYPE, \'de_DE.utf8\', \'German_Germany.utf-8\', \'de_DE\', \'german\'));
var_dump(m         


        
4条回答
  •  不知归路
    2020-11-27 08:57

    Even in UTF-8 mode, standard class shorthands like \w and \b are not Unicode-aware. You just have to use the Unicode shorthands, as you worked out, but you can make it a little less ugly by using lookarounds instead of alternations:

    /(?

    Notice also how I left the curly braces out of the Unicode class shorthands; you can do that when the class name consists of a single letter.

提交回复
热议问题