← Winnitude! Search  ·  Reader Mode (1438 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 9 LINKS

Illegal escaping on a Perl-style hex notation example on https://dev.java/learn/regex/intro/ · Issue #272 · java/devjava-content

Repository navigation

Illegal escaping on a Perl-style hex notation example on https://dev.java/learn/regex/intro/  #272


New issue

New issue

Open

Open
Illegal escaping on a Perl-style hex notation example on https://dev.java/learn/regex/intro/ #272

Description

@willy-b's profile willy-b opened on Aug 13, 2026

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions