简体   繁体   English

在Java中使用正则表达式进行希伯来语文本解析

[英]Hebrew text parsing using regex in Java

I am trying to parse a Hebrew text, but I am not getting any success. 我正在尝试解析希伯来语文本,但没有获得任何成功。 Can anyone here please help ? 这里有人可以帮忙吗?

    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

Thanks 谢谢

This, 这个,

Matcher matcherHebrew = pattern.matcher(hebrewSearhString);

Should be 应该

Matcher matcherHebrew = patternHebrew.matcher(hebrewSearhString);

And I get the output, 我得到了输出,

Whole -חן

Because the if does evaluate to true . 因为if评估结果为true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM