Skip to content

Feature: Support regex flags in tags.Pattern (for Unicode property escapes) #1699

@knoan

Description

@knoan

Feature Request

Problem

The tags.Pattern type does not support regex flags. This prevents using Unicode property escapes (\p{ID_Start}, \p{ID_Continue}) which require the u flag.

Use Case

Validating ECMAScript identifiers per UAX #31 requires Unicode property escapes:

// Standard JavaScript approach
const pattern = /^[\p{ID_Start}_$][\p{ID_Continue}_$]*$/u;

// With typia - no way to specify the 'u' flag
type Identifier = string & tags.Pattern<"^[\\p{ID_Start}_$][\\p{ID_Continue}_$]*$">;

Current Workaround

Manually expand all Unicode character ranges from DerivedCoreProperties.txt:

const ID_Start = [
    "\\u0041-\\u005A", // Latin uppercase
    "\\u0061-\\u007A", // Latin lowercase
    "\\u00C0-\\u00D6", // Latin Extended
    // ... 448 ranges total for full BMP coverage
].join("");

type Identifier = string & tags.Pattern<`^[_$${typeof ID_Start}][_$0-9${typeof ID_Start}]*$`>;

This workaround:

  • Produces unreadable generated code
  • Cannot cover astral planes (characters > U+FFFF)
  • Requires manual updates when Unicode standard changes

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions