I have this string
名古屋市北区,大曽根3丁目 13-2V-
in UFT-8 encode, I want to replace (or delete) only japanese numbers with latin numbers
expected result
名古屋市北区,大曽根3丁目 12-2V-
or
名古屋市北区,大曽根丁目 -V-
how can I do it in laravel?
>Solution :
Use regex :
$words = '名古屋市北区,大曽根3丁目 13-2V-';
$words = preg_replace('/\d+/u', '', $words);
dd($words);
Output :
"名古屋市北区,大曽根丁目 -V-"
Explain :
\d+
\dmatches a digit zero through nine in any script except ideographic scripts+matches the previous token between one and unlimited times, as many times as possible, giving back as needed (greedy)
Global pattern flags
umodifier:unicode. Pattern strings are treated asUTF-16. Also causes escape sequences to match unicode characters