On the latest version of https://dev.java/learn/regex/intro/ (archived as is at https://megalodon.jp/2026-0814-0023-31/https://dev.java:443/learn/regex/intro/ , snippet may not show on the archiver but should be in the html )
- For the Perl-style hex notation example for matcher patterns:
String hexPattern = "\x{" + Integer.toHexString(codePoint) + "}";
The example appears to be invalid due to illegal escaping (I have reported other typos in this series (at #212 ) , but did NOT author or modify this content):
jshell> String hexPattern = "\x{" + Integer.toHexString(codePoint) + "}";
| Error:
| illegal escape character
| String hexPattern = "\x{" + Integer.toHexString(codePoint) + "}";
| ^
I think it should be:
String hexPattern = "\\x{" + Integer.toHexString(codePoint) + "}";
so that one, using "\x{...}" instead of "\x{...}" can successfully match:
jshell> int codePoint = 0x6771;
codePoint ==> 26481
jshell> String hexPattern = "\\x{" + Integer.toHexString(codePoint) + "}";
hexPattern ==> "\\x{6771}"
jshell> "\u6771"
$37 ==> "東"
jshell> "\u6771".matches(hexPattern)
$38 ==> true
Thanks!
On the latest version of https://dev.java/learn/regex/intro/ (archived as is at https://megalodon.jp/2026-0814-0023-31/https://dev.java:443/learn/regex/intro/ , snippet may not show on the archiver but should be in the html )
The example appears to be invalid due to illegal escaping (I have reported other typos in this series (at #212 ) , but did NOT author or modify this content):
I think it should be:
so that one, using "\x{...}" instead of "\x{...}" can successfully match:
Thanks!