Java中使用正则表达式的希伯来文文本解析
我试图解析希伯来文文本,但没有获得任何成功。这里有人能帮忙吗Java中使用正则表达式的希伯来文文本解析,java,regex,parsing,hebrew,Java,Regex,Parsing,Hebrew,我试图解析希伯来文文本,但没有获得任何成功。这里有人能帮忙吗 String hebrewSearhString = "חן"; //String regexHebrewPattern = "([\\u0591-\\u05F4\\s]+)"; // Tried this too, but same no success String regexHebrewPattern = "([\\p{InHebrew}]+)"; Pattern patternHebre
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
谢谢你
Matcher matcherHebrew = pattern.matcher(hebrewSearhString);
应该是
Matcher matcherHebrew = patternHebrew.matcher(hebrewSearhString);
我得到了输出
Whole -חן
因为if的计算结果为真。谢谢@Elliot。那是一个愚蠢的错误。在这段代码上面,我使用“pattern”变量还有其他用途。