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, binary Unicode properties like \p{Alphabetic}) raise real.error rather than silently falling back to a backtracking engine, so a compiled pattern is a ReDoS-safety guarantee, not a maybe. (\p{L} / \p{sc=Greek} — General_Category and Script — are supported, a superset of stdlib re.) 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.24.tar.gz (288.8 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.24-cp310-abi3-win_amd64.whl (597.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

real_regex-2026.7.24-cp310-abi3-win32.whl (576.1 kB view details)

Uploaded CPython 3.10+Windows x86

real_regex-2026.7.24-cp310-abi3-musllinux_1_2_x86_64.whl (2.8 MB view details)

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

real_regex-2026.7.24-cp310-abi3-musllinux_1_2_aarch64.whl (2.7 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

real_regex-2026.7.24-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.7 MB view details)

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

real_regex-2026.7.24-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (1.7 MB view details)

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

real_regex-2026.7.24-cp310-abi3-macosx_11_0_arm64.whl (393.9 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

real_regex-2026.7.24-cp310-abi3-macosx_10_9_x86_64.whl (402.0 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: real_regex-2026.7.24.tar.gz
  • Upload date:
  • Size: 288.8 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.24.tar.gz
Algorithm Hash digest
SHA256 60c289b8ce68dd01fecf25de8d4b1c1d1b026eb3ed553fc2e6c1ac52a530df6b
MD5 4e2da0767488cf175848b3c2c124e2c5
BLAKE2b-256 d08907005503ddfb8fc1f055dfea3c30621867e49cc186bb74b9e2c83ac4bab0

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.24.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.24-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for real_regex-2026.7.24-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2d33e59f6e8dc6163caddb6a880bf01715b28b26dd8198a50460a3198e7f8e24
MD5 d4947395ea7ea545c3d48e86a6acac54
BLAKE2b-256 1713a012717fa710b55a4502bf277825f81beab6e795fcacc618ee7ce65fbff8

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.24-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.24-cp310-abi3-win32.whl.

File metadata

  • Download URL: real_regex-2026.7.24-cp310-abi3-win32.whl
  • Upload date:
  • Size: 576.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.24-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 6078ede5f364df41f9d625eb8ba7f655e8af9bd9c11b046cc3c2319e20b871fb
MD5 a1ccca0df32457b93f3d2d9956c61f85
BLAKE2b-256 f8ecaf5fd0848a6fae0fd48f8f9b8a1171118fc26f3c8b5fc40aa8eda51892c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.24-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.24-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for real_regex-2026.7.24-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6ce8ba38dcf80c0d31c6b3b64151be08dcac064d646376aa181804cef67e89e8
MD5 df0caeea27ce91202bef6f853a88525b
BLAKE2b-256 958edad1003c8784f39f38aebe12848fcaaacb8e7b972dae32a3bcbfacd6590b

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.24-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.24-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for real_regex-2026.7.24-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 058da4441a041edb7d203bdfea6d7c5e9e7cc1d0883e94ce8c242b3380d68e3e
MD5 e9ba0d52dab404bc76066f465b070a36
BLAKE2b-256 55abea56ba238071fb38607a487531da835542a944dfd77f8e16ce07a2c1168e

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.24-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.24-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for real_regex-2026.7.24-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 50a1467701526286855b7537a40a34d11cd8b70b6e567390dda08598fd530457
MD5 45e44127aff91d2c7a48587693d717ef
BLAKE2b-256 fd5b2c016de61f3fc4c3720fe5e1b6ca10012f770bf188769a2a3fd411c52fb1

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.24-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.24-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for real_regex-2026.7.24-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a70637d4c2c41914fb80213d5445bef4e2c4af7bf14e70b32e6fafadc1603013
MD5 d6c276f10dd18c3b2c035628a3738108
BLAKE2b-256 3f96a9b6e53b6c3441b24a7294eda0bd96082c499c43b24c909d70bba8803393

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.24-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.24-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for real_regex-2026.7.24-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 acee5f9e56380ea3944acad1cf495cedec041d0e9af6606fd2ccde87df37605f
MD5 7ae86a065d16562995cefd4020630a2c
BLAKE2b-256 a0622e4335058e77ff6596ca7970a6ca4f49237e6c50f239ba3ab098b05ae826

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.24-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.24-cp310-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for real_regex-2026.7.24-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5b36099ff51461d28641f2d81276c593a58b5b74cd79a538e97e1e204659fda7
MD5 f81f36de21e2fd412b31bae9f0a4ac67
BLAKE2b-256 63b6e77d92db9397cf4834600c9f5012436291d07f21a1dc82f415a14dfeb11e

See more details on using hashes here.

Provenance

The following attestation bundles were made for real_regex-2026.7.24-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