【问题标题】:Hebrew text parsing using regex in Java在 Java 中使用正则表达式解析希伯来语文本
【发布时间】:2014-10-09 05:55:58
【问题描述】:

我正在尝试解析希伯来语文本,但没有成功。有人可以帮忙吗?

    String hebrewSearhString  = "חן";

    //String regexHebrewPattern = "([\\u0591-\\u05F4\\s]+)"; // Tried this too, but same no success
    String regexHebrewPattern = "([\\p{InHebrew}]+)"; 

    Pattern patternHebrew = Pattern.compile(regexHebrewPattern, Pattern.UNICODE_CASE);
    Matcher matcherHebrew = pattern.matcher(hebrewSearhString);

    if(matcherHebrew.matches()) {
        System.out.println("Whole -"+ matcherHebrew.group(0));
        //System.out.println("Group 1 -"+ matcherHebrew.group(1));
        //System.out.println("Group 2 -"+ matcherHebrew.group(2));
    }

    Result : "If" condition doesn't gets to TRUE

谢谢

【问题讨论】:

    标签: java regex parsing hebrew


    【解决方案1】:

    这个,

    Matcher matcherHebrew = pattern.matcher(hebrewSearhString);
    

    应该是

    Matcher matcherHebrew = patternHebrew.matcher(hebrewSearhString);
    

    我得到了输出,

    Whole -חן
    

    因为if 确实评估为true

    【讨论】:

    • 谢谢@Elliot。那是一个愚蠢的错误。我在此代码上方将“模式”变量用于其他目的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-12
    • 1970-01-01
    • 1970-01-01
    • 2014-09-24
    • 2015-06-18
    相关资源
    最近更新 更多