Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

delete only japanese numbers laravel

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

名古屋市北区,大曽根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+

  • \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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading