Home > Enterprise >  delete only japanese numbers laravel
delete only japanese numbers laravel

Time:02-18

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?

CodePudding user response:

Use regex :

$words = '名古屋市北区,大曽根3丁目 13-2V-';
$words = preg_replace('/\d /u', '', $words);

dd($words);

Output :

"名古屋市北区,大曽根丁目 -V-"

Explain :

\d

  • \d matches 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

  • u modifier: unicode. Pattern strings are treated as UTF-16. Also causes escape sequences to match unicode characters

By the way, it works perfectly for :

  • Related