MC_delta_T
MC_delta_T

Reputation: 616

PHP regex Word Boundaries doesnt match end of string

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));

Upvotes: 1

Views: 227

Answers (1)

Federico Piazza
Federico Piazza

Reputation: 30995

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

Upvotes: 2

Related Questions