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.23.tar.gz (284.8 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.23-cp310-abi3-win_amd64.whl (592.5 kB view details)

Uploaded CPython 3.10+Windows x86-64

real_regex-2026.7.23-cp310-abi3-win32.whl (571.3 kB view details)

Uploaded CPython 3.10+Windows x86

real_regex-2026.7.23-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.23-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.23-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.23-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.23-cp310-abi3-macosx_11_0_arm64.whl (389.1 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

real_regex-2026.7.23-cp310-abi3-macosx_10_9_x86_64.whl (397.7 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: real_regex-2026.7.23.tar.gz
  • Upload date:
  • Size: 284.8 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.23.tar.gz
Algorithm Hash digest
SHA256 4373322ed7bb48d35c50157f9734fc28066ecc109f3ee1fbe37bfbf4794c1bb5
MD5 ef21a163fcf2f8dd6404e3a93f578a19
BLAKE2b-256 87fb8aebd06ec4cb41faa79aa02c691e3b65ac6bc97af3da17b0ab3b9898c58b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.23-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a5e0b961c84e1d480b8c5910d2a42bb08944351677e70214b274526fde38cfa0
MD5 a089a713a7ed3ec5617d62e9b4445936
BLAKE2b-256 11d9ae8b21d32d1b90bc41aa1db374679eb45e5625286bd6439a5cacffc8ac1c

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: real_regex-2026.7.23-cp310-abi3-win32.whl
  • Upload date:
  • Size: 571.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.23-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 d6529cb47ba6b4e2caa557af5585673575da81033ef896764ad98dabf6cb6422
MD5 5d886492a1b00c6fb6184c1f5a4dd337
BLAKE2b-256 ffb6652dc3cc514526502622e9595d10fbfe72aac5358e75e8e9c25e2219d046

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.23-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9ec85a293061c00263610bb5e7da2f1f203b7743acb38a967e873fc271b74c00
MD5 d4d5ef293760dc3138b68084d83cb294
BLAKE2b-256 61a3ab2eb6282f28ba465e295da757374cba5b2f049f3de1a2719f488341abf4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.23-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 a6a4fa337569e233a23ba87a6ed9d167643add6b2e2223bd180ae59b3f82f3d8
MD5 e07b7a20c6aa7e701ffe3ebf9f0a7837
BLAKE2b-256 7bb478a84a8c842f6df2d5cd4134cedcfacaf53d7fdbf14b9da083c1452abc82

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.23-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6be423ccb0edf9b2b70d4492083b67dc4b5a656b0125aad51af053268b7fc569
MD5 2e50c5dc822e9e69b638d0d9ac70f42f
BLAKE2b-256 4d3f3d38f5492a7d64cd93f2db29b5772d36cb983e6498df32776a6e9f6d60de

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.23-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c1a90d624f70e557cc40f9b7ace434a79c261500b72d750b17a55ff26b45c4a5
MD5 41503949f170faf5af9b6aceed01ea54
BLAKE2b-256 8ccc5bdc7738dbda81e6607fb97a09b2b11954e7befbcbeb969148294a41e25d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.23-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ccca3c767ab5709ed7862c57fcf9bf414a481eada328ed73bff1524f7541bfa5
MD5 fc26035b5ad9d67cf7c0780a4e4de14f
BLAKE2b-256 dd919a1921aefd1fc58fd71e635954b17318bc27701216f670f9c6ad79771a80

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.23-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 669f2673fda6bad45fb39b6e5a1235719fdc2b1a3a1fccc5eed59be4d1b1b087
MD5 4adc8a689f19797ccdfee3fefe511fd1
BLAKE2b-256 ddb67045b842ca89b5740109a28c3d6726f4208eab417662ec4dd844611a5240

See more details on using hashes here.

Provenance

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