使用preg_replace来表示日语

时间:2018-01-09 17:27:56

标签: php regex cjk

基本上我把一个从英语到日本的字符串翻译成这样:

$test1 = 1104 Notes receivable
$test2 = 1104 受取手形

我的目标是删除字符串前面的数字。我用这个regeX:

preg_replace('/^[^A-Za-z]+/', '', $test1)
output : Notes receivable

现在,日本人怎么样? 我需要这个字符串:受取手形

1 个答案:

答案 0 :(得分:4)

代码

See regex in use here

^\P{L}+

用法

See code in use here

<?php

$strings = ["1104 Notes receivable", "1104 受取手形"];
foreach($strings as &$string) {
    $string = preg_replace('/^\P{L}+/', "", $string);
}
var_dump($strings);

说明

  • ^在行首处断言位置。
  • \P{L}+匹配\p{L}不匹配的任何字符(相当于[^\p{L}]),一次或多次。 \p{L}是一个Unicode字符类,匹配任何语言/脚本中的任何字母。
相关问题