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.22.tar.gz (231.6 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.22-cp310-abi3-win_amd64.whl (511.5 kB view details)

Uploaded CPython 3.10+Windows x86-64

real_regex-2026.7.22-cp310-abi3-win32.whl (490.3 kB view details)

Uploaded CPython 3.10+Windows x86

real_regex-2026.7.22-cp310-abi3-musllinux_1_2_x86_64.whl (2.6 MB view details)

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

real_regex-2026.7.22-cp310-abi3-musllinux_1_2_aarch64.whl (2.6 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

real_regex-2026.7.22-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.6 MB view details)

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

real_regex-2026.7.22-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (1.6 MB view details)

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

real_regex-2026.7.22-cp310-abi3-macosx_11_0_arm64.whl (311.5 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

real_regex-2026.7.22-cp310-abi3-macosx_10_9_x86_64.whl (320.2 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: real_regex-2026.7.22.tar.gz
  • Upload date:
  • Size: 231.6 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.22.tar.gz
Algorithm Hash digest
SHA256 91a83eed4171c8cc8452bc4ceb1f5f5f0c4c4f022818ae8977c4b59e8155ebaa
MD5 a859ff31c3325516f5c34a8f61ad41d5
BLAKE2b-256 6c3e2348f156dcacfb51767725e0c54c245e07e925a4747d45d8f8085742963d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.22-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1322887227528f9e2f0161a4e5cde35b46f8c5ae55e2c3611a6601bac19c3f2f
MD5 136201cac7f1779656f52a2fca4309ff
BLAKE2b-256 3c7b960e437f9e841499daf20a35a20fd32b198297ac887ba1360706c446d860

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: real_regex-2026.7.22-cp310-abi3-win32.whl
  • Upload date:
  • Size: 490.3 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.22-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 4507ed388c69c97e44f1017843592b8b119345c8e284488ea733067eb8e74001
MD5 15723443ba8c911da1d9148696bfcbd4
BLAKE2b-256 1bf32b6f0a7d62fd29611e6e7bec9645d82bada5a0098d3999cfa455cbc524ca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.22-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b538905f45ac431d85c17b5d6fec4115add08afd9e6ffd29a699b4c0e2a50bf7
MD5 5c38cd3c49e72bd50686c2952a659acf
BLAKE2b-256 e2a71a5d79acf249153676c5a5061c13be7263b40fa0b209eebc6d70c1c2d2fb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.22-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 bd9d42aad40f0a34186c59b27d951a1de80d9a90ef530853485e0189ba2eb4c8
MD5 868b78b5a7b3f51725ee939426f5a718
BLAKE2b-256 5232daebf37c4bafa5aa06ab1b7f88ac30bd2e6a1fc788a0f6e5fd48c36884d6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.22-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 28e84b796d2df7e116c465144fbf3c73233b5821be9efbd7eda271ed1c1ec0df
MD5 5136cc91235aa11d5d1f0ab7bdc5abbe
BLAKE2b-256 e72b8f97fa24c316df5be483a13e5dab1a4ba722c99703bb674bfe8d8fc39c15

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.22-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3e0a0005f9dba7dbbdbefead85ab61847563eb895dfac7b2d9cdd4e968a77bf5
MD5 886c2cd7f9bf1454f233374b89f24d6a
BLAKE2b-256 4fd9e13033c642e78c40235cd036ca9abda163d11a636ad52c7ce9ffb4250e61

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.22-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 103af9370edfd34f00243f1f4fe046268e326466e06563bb73d3bca273cae036
MD5 e84ab20b83e9c9940b9c14d85e43ce25
BLAKE2b-256 2b05274dba392e68b8d23ba6b24f0ef108245db9ff64ddb3168a97c28b01a35c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.22-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e3e7d2abd6cb55c4db68139c70d2ddf3d977a7bf1e2b01c7c1a81c610e7b3d68
MD5 57387309cac8b21cf1851f5d0851130d
BLAKE2b-256 990b087e1d05c9aed86a4de9f66dc328e9b4cafc36fee14ed094a16e67510b13

See more details on using hashes here.

Provenance

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