1

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));
5
  • 2
    The two works well for me and return 1 as expected. eval.in/354283 Commented May 13, 2015 at 13:29
  • 1
    There's no problem with \b .See here regex101.com/r/mT0iE7/9 Commented May 13, 2015 at 13:34
  • 1
    A word boundary matches position before the first word character in the string, after the last word character in the string, and between two characters in the string, where one is a word character and the other is not a word character, so both examples should work fine. Commented May 13, 2015 at 13:40
  • i think reason is version differences. my local server has an old php 5.2 but actual server has newer version and its worked normally. thanks for efforts. Commented May 13, 2015 at 13:52
  • additional info: php regex processor thinks İ (big letter I with dot - turkish special chars) is a word boundary. Commented May 13, 2015 at 13:59

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.