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

前端 未结 2 495
挽巷
挽巷 2021-01-21 16:22

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

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

Text:

相关标签:
2条回答
  • 2021-01-21 17:14

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

    /\b(cum)\b/iu
    
    0 讨论(0)
  • 2021-01-21 17:15

    To deal with unicode, replace \b with

    /(?<=^|\PL)(cum)(?=\PL|$)/i
    
    0 讨论(0)
提交回复
热议问题