TomSawyer
TomSawyer

Reputation: 3820

How to use regular expression to match case insensitive unicode character?

I'm trying to use regular expression with php to match both upper case and lower case unicode character.

Here is my example code:

$s = "a à À";
$s = preg_replace("/à/iU", "a", $s);
echo $s;

But didn't success, anyone can help?

Upvotes: 2

Views: 821

Answers (1)

anubhava
anubhava

Reputation: 785068

This works:

$s = "a à À";
echo preg_replace('/à/iu', "a", $s);

Output:

a a a

Use /u not /U flag for unicode characters in your regex. U is for un-greedy (lazy) matching.

Upvotes: 4

Related Questions