混合字符串希伯来语和英语并捕获前 10 个字符完整到最后一个单词

mixed string Hebrew and English and catch the first 10 chars complete to last word

我有一个希伯来语和英语的混合字符串,我想抓住前 10 个字符而不在中间删掉一个字。例如:

    >שלום is peace not a war

我使用:

/^[a-zA-Z\-\u0590-\u05ff ]{1,10}\b/i

我的结果:שלום is [0-7]

没有 b 标志的结果是:שלום is pe [0-9]

要求的结果是:שלום is peace [0-12]

谢谢

您可以使用 \p{Hebrew} 属性 来匹配希伯来字符。

$re = '/^[a-zA-Z\p{Hebrew} ]{10,}?\b/mu'; 
$str = "שלום is peace not a war"; 

preg_match_all($re, $str, $matches);

print_r($matches[0]);

RegEx Demo