douzhigan1687 2015-05-13 13:21 采纳率: 0%
浏览 55
已采纳

PHP正则表达式Word边界不匹配字符串的结尾

i want to find an exact word has been a string. but if its end of the string, word boundaries failing. i thought because of special turkish chars but second code works expected. where is my mistake?

this code returns 0

$row = "TEDARİKÇİ,MÜŞTERİ";
var_dump( preg_match('#\bMÜŞTERİ\b#iu', $row));

but this one returns 1

$row = "TEDARİKÇİ,MÜŞTERİ";
var_dump( preg_match('#\bMÜŞTERİ$#iu', $row));
  • 写回答

1条回答 默认 最新

  • duanmian1085 2015-05-13 13:48
    关注

    I though both regex should work but I got same problem as you in regex101. So, in order to fix this you can change your regex to:

    $row = "TEDARİKÇİ,MÜŞTERİ";
    var_dump( preg_match('#\bMÜŞTERİ(\b|$)#iu', $row));
    

    Working demo

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区
  • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示