Regular expression - PCRE (PHP) - word boundary (\b) and accent characters

懵懂的女人 提交于 2020-07-31 03:55:05

问题


Why does the letter é count as a word boundary matching \b in the following example?

Pattern: /\b(cum)\b/i

Text: écumé

Matches 'cum' which is not desired.

Is it possible to overcome this?


回答1:


It will work, when you add the u modifier to your regex

/\b(cum)\b/iu



回答2:


To deal with unicode, replace \b with

/(?<=^|\PL)(cum)(?=\PL|$)/i


来源:https://stackoverflow.com/questions/22068702/regular-expression-pcre-php-word-boundary-b-and-accent-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!