Phil
Phil

Reputation: 47

find a regexpression that matches word boundaries that include accented letters

I need a regular expression to use in preg_match that will catch words like cialis when as a word with spaces and also as a word with a tag up close ie <b>cialis</b>, so I used this

$word = "cialis";
if (preg_match_all("/\b$word\b/i", $content, $matches)) {
        $caught[] = $matches[0];
    }

Which worked great and didn't fire with words like specialist that have cialis in them. All was fine until I hit some french words such as spécialisé The é is treated as if its a word boundary and so spécialisé gets caught. What regex would stop spécialisé being added to $caught?

Thank you in advance.

Upvotes: 1

Views: 111

Answers (1)

Kasravnd
Kasravnd

Reputation: 107307

You can use modifier u for unicode strings :

/\b$word\b/iu

Upvotes: 4

Related Questions