v160 · javascript · regexp
Portable pattern import
The proposal’s portability argument, end to end. Editor grammars, linters and form schemas ship regexes as JSON strings written for PCRE or Oniguruma, where \A/\z/\Z are everyday syntax. This page imports such a config, compiles it with u, feature-detects, and — only where the engine refuses — transpiles the escapes to their RegExp-modifier desugarings as a labelled fallback. It then scans a document and wires the config’s field pattern into a real <input pattern>.
1. Import the config
| Rule | Compiled as | Effective regex | Matches (line:col text) |
|---|---|---|---|
| Not imported yet. | |||
2. Use the config’s field pattern in a form
HTML compiles pattern as ^(?:pattern)$ with the v flag. If that fails to compile the attribute is ignored and every value is valid — so on an engine without buffer boundaries, a pattern using \A silently stops validating.
the transpiler
It walks the source once, skipping escaped characters and tracking (nested v-mode) character classes, and replaces only top-level \A, \z, \Z with the explainer’s desugarings: (?-m:^), (?-m:$), (?=(?:\r\n|\n|\r|
|
)?(?-m:$)). It needs RegExp modifiers (Chrome 125+). It is a migration aid, not the feature — rows that used it are labelled fallback.
see also
- Regular Expression Buffer Boundaries — feature index
- Assertion position map — proves the desugarings agree
- Annex B literal trap — what the naive strategy does
- ChromeStatus entry
- HTML — the pattern attribute (v flag compilation)
- Explainer — relationship to RegExp modifiers