【问题标题】:mixed string Hebrew and English and catch the first 10 chars complete to last word混合字符串希伯来语和英语,并捕获前 10 个字符完整到最后一个单词
【发布时间】:2015-11-26 16:11:47
【问题描述】:

我有一个混合字符串希伯来语和英语,我想捕捉前 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]

谢谢

【问题讨论】:

    标签: php regex utf-8 pcre


    【解决方案1】:

    您可以使用\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

    【讨论】:

    • 没有。这会在 PHP 中返回一个空 var。
    • 你说得对,我再次检查并发现我的页面编码有问题。谢谢你的回答对我帮助很大,你的坚持也很重要。
    猜你喜欢
    • 1970-01-01
    • 2012-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多