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

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

real_regex-2026.7.19-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.19-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.19-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.19-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.19-cp310-abi3-macosx_11_0_arm64.whl (294.2 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

real_regex-2026.7.19-cp310-abi3-macosx_10_9_x86_64.whl (300.4 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: real_regex-2026.7.19.tar.gz
  • Upload date:
  • Size: 222.2 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.19.tar.gz
Algorithm Hash digest
SHA256 5c0f0a9d5451e033e9bc5f45fbb6592f6aaf85be708659cb8966fd40cd9ac97e
MD5 2bf63949299844ea169c3c313af20781
BLAKE2b-256 07887c50fb495f4f19a137752151bf6bf066f9749e03e7b3ea89cfe8b48780c1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.19-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 577a481c90b4963a3e8b8abd0d5f7e7b3514a2d126afa7fdd69089595fecc74f
MD5 b93dca3a3034b159cf534ba68f2cfc80
BLAKE2b-256 b09575e3764fe2f14f67e86175ecb29176fd3b6a04053b05746f993d79c4fb5a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: real_regex-2026.7.19-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.19-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 2e7abcefb57dce98ae979996863ca88626ae8d570e67bb03fa4df1a626933ee9
MD5 f8f9da6d8a73a5e7836eb4722d71527d
BLAKE2b-256 caa9520dab4a917a4148d90c15152a1303787dc9aa45e8c3af1e892bc0334b63

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.19-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d2963921391f196ddbdab4145862f600f9f6dff619f0063a3452f8bc401436cf
MD5 eea44f168401770cee8f73a15d851673
BLAKE2b-256 486ee11663190c1790bce3e231d84062e3bed80171fab852812e8979219082db

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.19-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 354ff6b36a1b731faa6e4506978c268d221e215f9beba16e4b1e7d9006a4e752
MD5 ce554acf191f2b1d21a9478c48cac7b6
BLAKE2b-256 7793cad0e4b172b7d55fe725fbd322aa38cbb4dac77bc6e285ac61d3d24ac092

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.19-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 eb038a2c54187d6a1f8ad0ec64e0f92eac1ac5764f1de9047d6bf30a54206c25
MD5 cfd65cb677858e33dbe96da910b6363f
BLAKE2b-256 96ad169f9174a07ac3cabc684497450b940ee7f6c3c62dffc55ddf4e3eb65387

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.19-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f642c3cc124da833dfb480dbae552c58dc1a0090beb6cebf5f60d82af83b0fa2
MD5 0baf18b538ac543df2b5005f5666bebd
BLAKE2b-256 721534fcf3cf9c829d175af47dd947a6f4f102930c6cfc6246f1c350350f7988

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.19-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4aa2cb25cf2eed54a0182b9657ae9e4ccfd60f0f521b3f042171de807466ee8e
MD5 c86fe13d88322e79b23c91cd1dfbcacb
BLAKE2b-256 a373fa882a0751a25eea7c61d1ff5a81887ead2388745796ff7c468a027d652a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.19-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 23261502f3f8862361c7cb5a619d34cede459db24f888433ac8ef023fd25e5cb
MD5 d3fd60bfb1c8d1664b8a018d884e26a2
BLAKE2b-256 30801166dd35c4aad3606a2e03f77dafe7a3ebb9aa69e687f2f71f2602a0d648

See more details on using hashes here.

Provenance

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