# `JSONSchex.Compiler.ECMARegex`
[🔗](https://github.com/xinz/jsonschex/blob/main/lib/jsonschex/compiler/ecma_regex.ex#L1)

Handles compilation of ECMA-262 regular expressions for use in Elixir/PCRE.

The current implementation targets coverage of the optional `ecmascript-regex.json` test suite
of draft2020-12. Be aware that some ECMA-262 syntax features may not be fully supported
or perfectly translatable to PCRE.

This module normalizes ECMA-262 regex features (like property names) to PCRE equivalents
and expands whitespace shorthands to match ECMA-262 definitions while maintaining
ASCII semantics for other character classes where required.

Unicode General Category (gc) mappings are derived from the
[Unicode Property Value Aliases](https://unicode.org/Public/UCD/latest/ucd/PropertyValueAliases.txt).

# `compile`

Compiles a regex string with ECMA-262 compatibility adjustments.

Returns `{:ok, Regex.t()}` or `{:error, term}`.

## Examples

    iex> {:ok, regex} = JSONSchex.Compiler.ECMARegex.compile("\p{Letter}")
    iex> Regex.match?(regex, "a")
    true

    iex> {:ok, regex} = JSONSchex.Compiler.ECMARegex.compile("\p{Script=Latin}")
    iex> Regex.match?(regex, "a")
    true

    iex> {:ok, regex} = JSONSchex.Compiler.ECMARegex.compile("[^]")
    iex> Regex.match?(regex, "\n")
    true

    iex> {:ok, regex} = JSONSchex.Compiler.ECMARegex.compile(~S"a\/b")
    iex> Regex.match?(regex, "a/b")
    true

---

*Consult [api-reference.md](api-reference.md) for complete listing*
