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.17.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.17-cp310-abi3-win_amd64.whl (492.1 kB view details)

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

real_regex-2026.7.17-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.17.tar.gz.

File metadata

  • Download URL: real_regex-2026.7.17.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.17.tar.gz
Algorithm Hash digest
SHA256 66eb61ec4663053320db1768e453646e2b5378b2789829648864f9e58e1dc30d
MD5 526d8ac128a0e32a5feb81a076838901
BLAKE2b-256 811b5297db195562840a22a011703b18458e2aff58194682be7175703625c881

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.17-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1fa7322b614d95fd5ca9b07e15f6d306672ea7865589f596b6bdf9ca05d11802
MD5 b61d833f7c53fa9e1d88a1eddf7c75e5
BLAKE2b-256 2e80f270ff96274df7d26a2d0c78fb7160e38cc90676c0e55d9329d86af30c86

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: real_regex-2026.7.17-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.17-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 604d1cf874c707ebf83c93bbfe2d80183084b57e2105758ee8b0a64054f0d65a
MD5 d9b09463d22f3b62fe94ade4f0192074
BLAKE2b-256 a92500034622268fad6e3d9e9508349d2f19c4f807e2a139e83716e36c87d4cb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.17-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3d82daa1491ef23ad541849b078609ec6af9a9bb9bf995e1915b039ec17f9db2
MD5 66d624a5bd8af9dd611e7ba966ee96cb
BLAKE2b-256 a827f97048101136d6c873849fff625071098020c2873aa1dfe59a5609808761

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.17-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7d9d02968b4221dda7c95a49266b1af31ea8e0e35455b0c6f4f6ccf754b29c09
MD5 86bc80aabdca09e0c5fc3fe561f3487a
BLAKE2b-256 153c200a73ed3db315f38bcb6277aeee738cb66515d90222eb7fd0c3b1516271

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.17-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bdd53aae9d9053475def90f6d0615509a319f47d66a2f7edb3f051e7698d107a
MD5 d58b8b101a7eba79caac6fd90924f6fe
BLAKE2b-256 e43e0994fbd638020fc1dd4a8ac389a5e91060b0d7ada2ace3183a9d55dbedcc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.17-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 42f56b39a472416386b0e68bdd2dfce629fc4dcc41ce6d3a35e472d0c773d0ba
MD5 681901b273fa4f71e5c68d383ef3cd7a
BLAKE2b-256 2ad0c557746830763b6287d4bf0653f7b93624f8f7d1f063d910029d02ea94f2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.17-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1776b50fb628373b68517086194403b7b2fe092a1e6fba7fad485304d03dfccd
MD5 52047f3eabb646d4f7c37251f872625c
BLAKE2b-256 39f1537c613097b834b9f863ff993b2ad8009f37422f144d16924999ea480ae7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.17-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2b442fe5873f96baf9ba4d4ccad8ca3b1261fcdda8f3b30654b899e39e21da2c
MD5 63b1b44ad27aa31afba1fc5faacda8f0
BLAKE2b-256 8415593a20319e08d834fa0fc54f9a51df6b23a87255c3227043537f11843bf0

See more details on using hashes here.

Provenance

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