Skip to main content

corvus-regex-ecma262 for Python

Regular expressions with the grammar and the answers of ECMA-262, the RegExp of JavaScript, for Python: the corvus-regex-ecma262 Rust crate, as a typed package with wheels for Linux (glibc and musl), macOS and Windows, x64 and arm64, for every Python from 3.10.

  • Every flag: d, g, i, m, s, u, v and y, with the grammar of each. Without u or v a pattern is read by the Annex B grammar and matched by UTF-16 code unit, as ECMA-262 matches it; with them, by code point. The v flag has nested classes, the difference and the intersection of classes, strings in a class and the properties of strings.
  • ECMAScript 2025: lookbehind, named groups (and a name shared between alternatives), modifier groups such as (?i:...), and every Unicode property ECMA-262 lists, from Unicode 17 tables the crate carries.
  • str, bytes (UTF-8) and array.array('H') (UTF-16 code units, as JavaScript holds a string). A pattern answers as it does in a browser or Node, which Python's re does not: \d, \w, \b, . and $, case folding, \p{...} and the rest read as JavaScript reads them.
  • Every match runs without the GIL. A pattern without a backreference is matched in time proportional to its size times the text, and a pattern can be given a match timeout, as a Regex of .NET can, which every method honours and which caps the backtracking memory too, so with a timeout neither a pattern nor a text from outside can make a program hang.

Compliance. Over the ECMA-262 test data (what V8 says about 123,087 patterns and 6,056,699 texts, test262's and exec, the global search, replace and split among them, and texts of bytes that are not UTF-8, which it refuses), through this package over str, bytes and code units, it gives 29,289,554 right answers, every answer the data asks, and none wrong, refuses no valid pattern, accepts no invalid one and reaches no limit. CI runs the whole data on Linux and Windows on every change. (A search that starts between the two halves of a character beyond the Basic Multilingual Plane, which a str position cannot name, is asked over code units.)

Install

pip install corvus-regex-ecma262

Getting started

import corvus_regex_ecma262 as ecma

# The flags are those of new RegExp(pattern, flags).
date = ecma.compile(r"(?<year>\d{4})-(?<month>\d{2})", "gu")

date.test("due 2026-10")                               # True
m = date.search("due 2026-10")
m["year"], m.span(), m.groupdict()                     # '2026', (4, 11), {'year': '2026', 'month': '10'}

# Every match of a global search, as matchAll makes it.
[m.group() for m in date.finditer("2026-10, 2027-01")]  # ['2026-10', '2027-01']

# replace replaces every match with the g flag, and the first without it; a function may give each replacement.
date.replace("2026-10, 2027-01", "$<month>/$1")        # '10/2026, 01/2027'
date.replace("2026-10", lambda m: m["month"])          # '10'

# split splices in what the groups captured; a group that did not take part is None.
ecma.compile(r"\s*(;)\s*").split("a ; b;c")            # ['a', ';', 'b', ';', 'c']

The API

compile(pattern, flags="", *, timeout=None), Regex(...) Compiles a pattern as new RegExp(pattern, flags) does; raises error when it is not valid. timeout is the match timeout in seconds (0 for none; None for default_timeout()).
set_default_timeout(seconds), default_timeout() The timeout of every pattern compiled without one: None (no limit) unless set.
is_valid(pattern, flags="") Whether a pattern is valid, without compiling it.
Regex.test(string, pos=0, *, timeout=None) RegExp.prototype.test with lastIndex at pos (at pos alone with y).
Regex.search(string, pos=0, *, timeout=None) The first match at or after pos, as exec finds it: a Match, or None.
Regex.finditer(string) A global search as matchAll makes it: an iterator of Match.
Regex.replace(string, replacement) String.prototype.replace: the first match, or every match with g; the replacement is a template or a function of the Match.
Regex.replace_all(string, replacement) String.prototype.replaceAll: every match.
Regex.split(string, limit=None) String.prototype.split: a list of strings, None for a group that did not take part.
Regex.pattern, .flags, .timeout, .groups, .group_names What the pattern is.

A Match is read as an re.Match is: group(*groups), m[g], groups(default), groupdict(default), start(g), end(g), span(g) (a group that did not take part is None, at -1), string and re; a group is a number or a name.

Positions. Over a str positions are code points, as Python indexes it; over bytes they are bytes of UTF-8. Without u or v a pattern is matched by UTF-16 code unit, so a match can take half of a character beyond the Basic Multilingual Plane, as in JavaScript: over a str its text holds that half as a lone surrogate, as a JavaScript string would, and its start and end are the whole character's; over bytes the position between the halves is the character's third byte. A str may hold lone surrogates; a lone surrogate written into a pattern is read as U+FFFD (write it as the escape \ud800 to match one).

Code units. An array.array('H') is UTF-16 code units (in the machine's byte order, as array keeps them), matched as they are, positions in code units: the text as JavaScript holds it, so a position between the halves of a character can be given (search(units, 1) after a character beyond the Basic Multilingual Plane) and is given back as it is. Every method takes one; a group, a piece of split and the result of replace are arrays of code units, and a replacement may be one or a str. array.array('H', s.encode('utf-16-le', 'surrogatepass')) makes one from a str on a little-endian machine.

Errors. error (a ValueError) says why a pattern did not compile in its message and in kind: "pattern", "flags" or "too_large". A match that reaches its timeout, or its cap on backtracking memory, raises MatchLimitError, a kind of error, from whichever method matched; a global search ends there. bytes that are not UTF-8 raise a plain ValueError, before any of them is read: none is matched, nor read as U+FFFD.

Timeouts. A pattern has a match timeout, as a Regex of .NET has: compile(pattern, flags, timeout=1.0), or for every pattern compiled after it set_default_timeout(1.0). Every method that matches gives each of its matches the timeout; test and search take a timeout= of their own in its place. Without a timeout (the default) a match has no limit of time or of memory, so a program that matches a pattern or a text it did not write should set one.

Threads. A Regex is immutable and may be used from any number of threads; matching releases the GIL.

Benchmarks

The Industry workloads of dotnet/performance, this package against Python's re, the regex package and V8, are on the central page, corvus-oss.org/corvus-regex-ecma262-benchmarks, measured nightly on one runner with every other Corvus ECMA-262 engine.

Repository

  • src/lib.rs: the binding (PyO3, abi3); python/corvus_regex_ecma262: the package and its type stubs.
  • tests/: the tests; tools/dataset.py: the test-data runner (python tools/dataset.py <data> wrong.tsv).
  • tools/bench: the benchmark harness and the script the image runs; Dockerfile: the image the central page runs.

Licence

Apache-2.0. See LICENSE.

Metadata

Release files for corvus-regex-ecma262 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for corvus-regex-ecma262 0.2.1
File Size Uploaded Provenance
corvus_regex_ecma262-0.2.1.tar.gz 53.5 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for corvus-regex-ecma262 0.2.1
File
corvus_regex_ecma262-0.2.1-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details
corvus_regex_ecma262-0.2.1-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
corvus_regex_ecma262-0.2.1-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
corvus_regex_ecma262-0.2.1-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
corvus_regex_ecma262-0.2.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
corvus_regex_ecma262-0.2.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
corvus_regex_ecma262-0.2.1-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl CPython 3.10 abi3 macOS 11.0+ ARM64, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64 Details

Total release size: 5.9 MB

Release files / corvus_regex_ecma262-0.2.1.tar.gz

Download URL corvus_regex_ecma262-0.2.1.tar.gz
Size 53.5 kB
Tags Source
SHA-256 checksum
How to use checksums
37e3f7982917a8c862878f93195e5d546b5382c35693945a0f997f8efa319355
BLAKE2b-256 checksum
How to use checksums
5c94a8c9f3bd2314cc767e4b6385a25b0dde6d49b0bbe825a8aaa96096616256
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / corvus_regex_ecma262-0.2.1-cp310-abi3-win_arm64.whl

Download URL corvus_regex_ecma262-0.2.1-cp310-abi3-win_arm64.whl
Size 555.4 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
43d7e5c9cf8d5e2aeaba960e3a21cbad5d33cbe674b61d7fc1a9845340dec223
BLAKE2b-256 checksum
How to use checksums
12f5298cdc84cd601444279d77f0f57054e59746d6fd2b9ffbcb062a850928a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / corvus_regex_ecma262-0.2.1-cp310-abi3-win_amd64.whl

Download URL corvus_regex_ecma262-0.2.1-cp310-abi3-win_amd64.whl
Size 633.7 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d9489fddbf2b755bf55860b17d4f0028d45ba87a026184f72271d2e950b678ab
BLAKE2b-256 checksum
How to use checksums
032f45e03b62e4315201c1d7df60a8d7247906b155224114b8d400dd68ea1075
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / corvus_regex_ecma262-0.2.1-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL corvus_regex_ecma262-0.2.1-cp310-abi3-musllinux_1_2_x86_64.whl
Size 967.1 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
1fde8323dfcdaea56068741f4c46da0c2b59e0af4d93eaa6743e4f30938f4500
BLAKE2b-256 checksum
How to use checksums
edddbf194d988ce4d69d09d6c51303677c9db7231a5ffdae8fe548e09112a377
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / corvus_regex_ecma262-0.2.1-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL corvus_regex_ecma262-0.2.1-cp310-abi3-musllinux_1_2_aarch64.whl
Size 869.2 kB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
0729c2113d2963deafd5cf04a1b4bcf050ee378e5927767ebf1d1595701c37c7
BLAKE2b-256 checksum
How to use checksums
0dfd9b3380fe31026f21f6c6d2be3035fd1336549560c6d89c99a51bf3216741
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / corvus_regex_ecma262-0.2.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL corvus_regex_ecma262-0.2.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 752.9 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
f0c38ec0f1321f897a2a12f3191b9eecd96556493678a29b8b8d3aa3a82f3481
BLAKE2b-256 checksum
How to use checksums
2bb67ae59408efe08f748c949be99e262414b2a128afef4277abb9e5c6e21be0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / corvus_regex_ecma262-0.2.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL corvus_regex_ecma262-0.2.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 690.9 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
d98f60fd4be6c4fb1c15f64879c1621b2c02c0dda462b641d64fdf7def82d75b
BLAKE2b-256 checksum
How to use checksums
618f0667116c8a1d138bf52672997a8953d3c89c6cfb316102f068abcb48f9f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / corvus_regex_ecma262-0.2.1-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Download URL corvus_regex_ecma262-0.2.1-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 1.4 MB
Tags CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
2a3afa1afd89180f172584cab38beb54ab7fcb69a27e2af9fa64ddb8f4b65c9a
BLAKE2b-256 checksum
How to use checksums
753348a6e74915d9a1645ed967892ec29b34d188bb38c0bb87ffb508dbe3313c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Security for corvus-regex-ecma262 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for corvus_regex_ecma262-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page