适用于希腊语扩展或希腊语脚本的 Java 正则表达式
原文: https://howtodoinjava.com/regex/java-regex-match-any-character-in-greek-extended-or-greek-script/
在本教程中,我们将学习匹配“希腊扩展” unicode 块或希腊语脚本一部分的任何字符。
解决方案正则表达式:
\\p{InGreek}
和\p{InGreekExtended}
匹配希腊文字中的任何字符
让我们看一个示例程序,该程序能够匹配字符串中希腊语脚本中的任何字符。
String content = "A math equation might be α + β = λ + γ";
String regex = "\\p{InGreek}";
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(content);
while (matcher.find())
{
System.out.print("Start index: " + matcher.start());
System.out.print(" End index: " + matcher.end() + " ");
System.out.println(" : " + matcher.group());
}
Output:
Start index: 25 End index: 26 : α
Start index: 29 End index: 30 : β
Start index: 33 End index: 34 : λ
Start index: 37 End index: 38 : γ
匹配“希腊扩展” unicode 块中的任何字符
让我们看一个示例程序,该程序能够匹配字符串中希腊语脚本中的任何字符。
String content = "Let's learn some new greek extended characters : ᾲ , ᾨ etc.";
String regex = "\\p{InGreekExtended}";
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(content);
while (matcher.find())
{
System.out.print("Start index: " + matcher.start());
System.out.print(" End index: " + matcher.end() + " ");
System.out.println(" : " + matcher.group());
}
Output:
Start index: 49 End index: 50 : ᾲ
Start index: 53 End index: 54 : ᾨ
参考:
http://en.wikipedia.org/wiki/Greek_alphabet
http://www.alanwood.net/unicode/greek_extended.html
https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html