2014-10-09 53 views
0

我想解析一個希伯來語文本,但我沒有得到任何成功。任何人都可以請幫忙嗎?在Java中使用正則表達式的希伯來文解析

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 

感謝

回答

0

Matcher matcherHebrew = pattern.matcher(hebrewSearhString); 

應該

Matcher matcherHebrew = patternHebrew.matcher(hebrewSearhString); 

而且我得到的輸出,

Whole -חן 

因爲if確實評估爲true

+0

謝謝@Elliot。這是一個愚蠢的錯誤。我在這段代碼上面使用了'pattern'變量來實現其他目的。 – 2014-10-09 06:35:55