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.25.tar.gz (292.9 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.25-cp310-abi3-win_amd64.whl (600.9 kB view details)

Uploaded CPython 3.10+Windows x86-64

real_regex-2026.7.25-cp310-abi3-win32.whl (579.4 kB view details)

Uploaded CPython 3.10+Windows x86

real_regex-2026.7.25-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.25-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.25-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.25-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.25-cp310-abi3-macosx_11_0_arm64.whl (399.6 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

real_regex-2026.7.25-cp310-abi3-macosx_10_9_x86_64.whl (411.7 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: real_regex-2026.7.25.tar.gz
  • Upload date:
  • Size: 292.9 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.25.tar.gz
Algorithm Hash digest
SHA256 74880c744ae43f5653d5e44f2ca704ef8493b9c0b40fbb5408b82ad47444e6d9
MD5 f181808c91e3026937f7924f52f4b624
BLAKE2b-256 5be16dd4dafcc30f21ead034eeb958dcf47e31c662e04c27739a8a96d8e3a66f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.25-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f156b51c668229162c3d92dfa03d1d9ea44888c12f5025052f6d04901397457d
MD5 de60efb641c89005b1ea2d7068902ad9
BLAKE2b-256 0bda0102bc66c8c010cf961ba592ef334d6f6e359b265182ee97847b1e83eca5

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: real_regex-2026.7.25-cp310-abi3-win32.whl
  • Upload date:
  • Size: 579.4 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.25-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 0a59b7e0bad6a88d6e705f56ecdfe192b85e0622d0bfb2478188bbba95e7e093
MD5 1e594365b5b29c301273f9cde53b5dd8
BLAKE2b-256 a9125cc3d6738178b96664c8d827c27f793c39f76c7a54eabc828a7283577f5b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.25-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b235c2455648c9ffefe7edd97dbeee0d854b17ff1e524c8919e040f8b0929ad9
MD5 cdafef2dcccb246ebb4cbce579380e6a
BLAKE2b-256 1a9f7579d4404c105b143435325618b3f54173f251a4afee19fa9d8c9fd62f5c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.25-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 b0e840c6ce020f8a3f650d67eff47c0cc15a5b28259e91b8623bfc50f9f963cf
MD5 c96ddf25cee5575a495b9d8de9002150
BLAKE2b-256 3063a2cfd5b3774f0bba8ec46cf0ddef7dbb605d95851a62ac2dd996381d62d2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.25-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 070b138c1188809953ba189563376d8fa3743baa6dc8b7bc4be4d713ad1f58aa
MD5 72a3f6b26fc674cddf2ef1383d0a5972
BLAKE2b-256 5b5f36f22372dc491e7fd4ebf5fccb36a95fb16f692bb833adbc76f3423f31be

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.25-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cc9614469b1fd2089fd0ac57a930b84e24b081ef3a91f67b80ac02ad21ca2aae
MD5 c51cce07db616f464999e599e5341673
BLAKE2b-256 7bc3c86170b49af0f6ba7a9f47de51e0edf970911b3bf8cd3e32dedd2ad4fd91

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.25-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 21bb3c9ba6caf316e2e748ec1b45a60cf11ec9730d334a1a8be50dbf30a4d74a
MD5 18526735b12b0b5fd81ddc952f7797d6
BLAKE2b-256 156701d6954c978f95d4379166b0dbaafe0024c3de550aabc800bb20fd0bf39c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.25-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2d7d8708fed451f530c5ad779e43e5d25a1fd942aa5034380a6e9558146acbbf
MD5 d8b65170aa159d3b172c48ee56a2d286
BLAKE2b-256 356fbc863d28e85e18d29732d5799fcae7fb048bb97db1cc27cd20743fc84362

See more details on using hashes here.

Provenance

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