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.18.tar.gz (222.1 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.18-cp310-abi3-win_amd64.whl (492.1 kB view details)

Uploaded CPython 3.10+Windows x86-64

real_regex-2026.7.18-cp310-abi3-win32.whl (473.5 kB view details)

Uploaded CPython 3.10+Windows x86

real_regex-2026.7.18-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.18-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.18-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.18-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.18-cp310-abi3-macosx_11_0_arm64.whl (297.5 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

real_regex-2026.7.18-cp310-abi3-macosx_10_9_x86_64.whl (306.2 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: real_regex-2026.7.18.tar.gz
  • Upload date:
  • Size: 222.1 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.18.tar.gz
Algorithm Hash digest
SHA256 b8eb6486557b7efe84c33e07a4d89a3b5321b5304d16d326dab855278ebc049d
MD5 f9299096c59db32191ec1934de290c89
BLAKE2b-256 dcd5a40b152002634cfa4ee2d98b0b5cd5273920cbf03bdb5fbc13a89e4985c0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.18-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a940403329cafec55c45b1a63bde3ac3107c31d7f541e968222cff3478dd0433
MD5 3ae8c51ba882f7ec5eb46d64b02d72e6
BLAKE2b-256 cdbc0132869d4d85985bc50e3ed252204b0c8296241e9a0e779dd5de25da5078

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: real_regex-2026.7.18-cp310-abi3-win32.whl
  • Upload date:
  • Size: 473.5 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.18-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 407cad8ebda7294613dac3fdf2121846e1e30df375a7f748727f0fc6bc249414
MD5 5a7a8af40920cfbab1d5990ad063e944
BLAKE2b-256 5ac8a4883fd9cf7d901928394774af79987f36ad61d46f9f4d19f5327e334044

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.18-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9598029666b16a99a5468af46d5e3320df0144554ba285e3c8b20c2a3e0dedad
MD5 7c025d3dae032157cb04b90a73cbc62c
BLAKE2b-256 97733d7106bd66627cdaaa90c94352b8e99a45011245ffa78a325315bc7d9828

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.18-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 98513cff574ea629de8e35d233ce996c66f3bc67a8868921f13cb3358814b08e
MD5 8f4eabb9c8c301b00b1bbb71876754fb
BLAKE2b-256 61224c4bd33e6fbaf448fc49d73af1c1f8837f49480fa481a983dc8078cc9b76

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.18-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1b5248666f3fdc1047c95ed1d80b9903728817ce7f03713e74b128f57feb00f5
MD5 6d7163d03f430911f099eeaa6d0bd81b
BLAKE2b-256 356d2c479b9e61a9fd70d529a7c229a887ac34bd7ddd32e4e33a86c3541abd38

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.18-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cf972b8470b2684fc8555cd1cc8b60f3b8bf811115e16b659ea31d328aa96823
MD5 e264222e37bea0ffb5f14bd96c4c8846
BLAKE2b-256 c36299921babef2e231f2c2b018ddad95eb8f8f43ffaf60c664f0c6c57f713cc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.18-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5735ba85c09a5149e8975836ad82a4d3eb1c9a66c80ca1ef93944daf4b0a0671
MD5 08699735fcd9613ba37993b9446f68c2
BLAKE2b-256 e7db44813a090e0863373355a85c270b859a595153c0eca2ac5d0bb29f68cfbb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.18-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 a59850f1510992b1cb563b1a67449e7659065eab746268d1f61501206bb0bc12
MD5 04373f63d5ffb19ad9fba26a37676d8c
BLAKE2b-256 424f67ae887d6deb5ef97ecd70ee0cc7a7d63c55a096c4033953777adbcc278b

See more details on using hashes here.

Provenance

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