Skip to main content

REAL — linear-time (ReDoS-safe) regex engine with an re-compatible API

Project description

real-regex

A drop-in replacement for Python's re, backed by a linear-time, ReDoS-safe C++20 engine — with bounded lookarounds that the other linear-time engines (RE2, Rust) don't have.

pip install real-regex

Drop-in for re

Import it as re and use the API you already know — compile, search, match, fullmatch, findall, finditer, sub, subn, split, and Match.group / groups / groupdict / span / start / end:

import real as re

m = re.match(r"(\w+)@(\w+)\.(\w+)", "user@example.com")
m.group(1), m.group(2), m.group(3)          # ('user', 'example', 'com')

re.findall(r"\d+", "a1 b22 c333")            # ['1', '22', '333']
re.sub(r"\s+", "_", "a  b   c")              # 'a_b_c'

Flags work the same: re.I, re.M, re.S, re.X, re.A. Unicode \w \d \s \b and IGNORECASE case-folding follow re in text mode.

Why replace re

  • No ReDoS. re (like every backtracking engine) blows up on patterns like (a+)+b against a hostile input — seconds, then minutes. real-regex is a Thompson NFA simulation: linear time, always, no catastrophic backtracking, ever.
  • Bounded lookarounds, still linear. (?=…) (?!…) (?<=…) (?<!…) — including variable-width lookbehind — match without backtracking. RE2 and Rust drop lookarounds to stay safe; real-regex keeps them.
  • Faster than re on most work — geometric mean 2.06× across a broad corpus (CI [1.37, 3.12]). One-pass extraction and a lazy DFA make sparse findall 9.6×, multiline anchors 30×, and capture-dense group extraction (emails: 1.07×, up from a 0.32× loss before the one-pass work) beat re; a couple of high-volume split/tiny-anchored cases stay slower (CPython's C engine wins there). It is not the fastest engine at raw throughput — it is the safe one that is also quick.

Not re, on purpose

Strict by default — every accepted pattern is guaranteed linear. The unsupported constructs (backreferences, conditionals, Unicode property classes \p{…}) raise real.error rather than silently falling back to a backtracking engine, so a compiled pattern is a ReDoS-safety guarantee, not a maybe. Opt into delegating those to the standard library re per call with real.compile(pat, fallback=True) (or module-wide with real.fallback = True) — it may accept them, at the cost of the linear-time guarantee for that pattern; Pattern.engine ("real" or "re") always tells you which backend you got. A few semantics differ deliberately (e.g. a nullable loop's final empty capture). Full list: COMPATIBILITY.md.

The wheel also ships the header-only C++ library — real.get_include() returns its path, so the same engine is available to C++ via #include <real/real.hpp>. Source, benchmarks and the C++ API: https://github.com/RECHE23/real-regex.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

real_regex-2026.7.21.tar.gz (222.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

real_regex-2026.7.21-cp310-abi3-win_amd64.whl (492.7 kB view details)

Uploaded CPython 3.10+Windows x86-64

real_regex-2026.7.21-cp310-abi3-win32.whl (474.1 kB view details)

Uploaded CPython 3.10+Windows x86

real_regex-2026.7.21-cp310-abi3-musllinux_1_2_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

real_regex-2026.7.21-cp310-abi3-musllinux_1_2_aarch64.whl (2.5 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

real_regex-2026.7.21-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

real_regex-2026.7.21-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

real_regex-2026.7.21-cp310-abi3-macosx_11_0_arm64.whl (294.8 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

real_regex-2026.7.21-cp310-abi3-macosx_10_9_x86_64.whl (300.8 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

Details for the file real_regex-2026.7.21.tar.gz.

File metadata

  • Download URL: real_regex-2026.7.21.tar.gz
  • Upload date:
  • Size: 222.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for real_regex-2026.7.21.tar.gz
Algorithm Hash digest
SHA256 3d97c9e7d406293558ee47e8f228418f83b9740b5a742fda9d0101b7bc601dbc
MD5 a152f47ccadf52fb23b030840455ceff
BLAKE2b-256 84e0c61a8aafe2bbace9eb7d95aca356917b52223392a3e668ec3849ab717097

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.21.tar.gz:

Publisher: release.yml on RECHE23/real-regex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file real_regex-2026.7.21-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for real_regex-2026.7.21-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 89a64a7a6227debb6527cf93eb0d07b01522f2c29223196b52b1ec11c187f46d
MD5 679275d0541813a2038b3f01c44ea7bb
BLAKE2b-256 0148e62165054cd29a05d5cb9d574a4c874a3dd917b5431625e864f3e07b60f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.21-cp310-abi3-win_amd64.whl:

Publisher: release.yml on RECHE23/real-regex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file real_regex-2026.7.21-cp310-abi3-win32.whl.

File metadata

  • Download URL: real_regex-2026.7.21-cp310-abi3-win32.whl
  • Upload date:
  • Size: 474.1 kB
  • Tags: CPython 3.10+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for real_regex-2026.7.21-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 f041e756aa859b1d28a39a7a199832a282f93e5cc1d3947cdada2a5e160afc60
MD5 18e4a15d504b56fcb9c103b201b1b3c8
BLAKE2b-256 6f145a24db071bcb7eeddb2cffbb9a45e6c11bea8de4ddcad245bf12eac9aff8

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.21-cp310-abi3-win32.whl:

Publisher: release.yml on RECHE23/real-regex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file real_regex-2026.7.21-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for real_regex-2026.7.21-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 290cdd633e2a386a4cb5a1497c5747888a78e1e13789e6e81fee485f642310ba
MD5 82e9d8a618ee3d4a3bcb860517738b54
BLAKE2b-256 2b8182c439311ab842a0d51b180d1c4fe5c4a4205a565dd958e42e1fad6412f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.21-cp310-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.yml on RECHE23/real-regex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file real_regex-2026.7.21-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for real_regex-2026.7.21-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 21ec68fbf1054a3e438b4eab0a563ee351c4cb30e0bd7228155319875f304816
MD5 f0cdc4cff8f60d07b0a0e04a19a21f92
BLAKE2b-256 945d97418e99f76ed84de68041076e9e46d4900e0431ca698c280fe7cb50a0a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.21-cp310-abi3-musllinux_1_2_aarch64.whl:

Publisher: release.yml on RECHE23/real-regex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file real_regex-2026.7.21-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for real_regex-2026.7.21-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ef54e371c7922a6d8144e5d21deb7fdf39bdb95379d9413e3009af7331cd6aec
MD5 e3bafcda8538850a11d933d1b30566ec
BLAKE2b-256 62405de5d51dae5e4fa7274cc61e3b2218a1b8e6b096015df0d5f8595626eba8

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.21-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on RECHE23/real-regex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file real_regex-2026.7.21-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for real_regex-2026.7.21-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 03dc7638c8246845812396233914ea2fa4663d7cca018ae01bddeb7709b0a653
MD5 2692d85bbcfcf5e914ca369fa907f638
BLAKE2b-256 6a57ca0e4fb1f7876013a982bb0ac0e3567eaf148ec10453bd2567f588cdb302

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.21-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.yml on RECHE23/real-regex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file real_regex-2026.7.21-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for real_regex-2026.7.21-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0b2be19a1c26f1d55072baf807019cb1e65992d426555fc4b3ec870a6cdd5103
MD5 14fb302ebddf4b7d661c6dece21ccb2d
BLAKE2b-256 136ae3ba841257cfcf97a7773170d28769b0d653eb0958edd9d04cbfa73e085a

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.21-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on RECHE23/real-regex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file real_regex-2026.7.21-cp310-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for real_regex-2026.7.21-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7bac1a239f078389779045e71cdc1378ec66ea1f61feefbeb7540a8a31a551ca
MD5 10b0b75b1c8ded0f7141c89065d63e0d
BLAKE2b-256 0804a963cce33d91a6ec78ab19c5d42cfea4b28ab30f589695a4b9c8af664cfd

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.21-cp310-abi3-macosx_10_9_x86_64.whl:

Publisher: release.yml on RECHE23/real-regex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page