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.
  • Fast on the common cases. One-pass extraction and a lazy DFA put capture-dense finditer and anchored fullmatch ahead of re, and validation/no-match scans several times faster. It is not the fastest engine at raw throughput (a JIT wins there) — 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.16.tar.gz (223.4 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.16-cp310-abi3-win_amd64.whl (492.0 kB view details)

Uploaded CPython 3.10+Windows x86-64

real_regex-2026.7.16-cp310-abi3-win32.whl (473.4 kB view details)

Uploaded CPython 3.10+Windows x86

real_regex-2026.7.16-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.16-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.16-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.16-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.16-cp310-abi3-macosx_11_0_arm64.whl (294.1 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

real_regex-2026.7.16-cp310-abi3-macosx_10_9_x86_64.whl (300.3 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: real_regex-2026.7.16.tar.gz
  • Upload date:
  • Size: 223.4 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.16.tar.gz
Algorithm Hash digest
SHA256 f3715ea54461840ac0b26cd36684d65372216e6a310a57410565b7e06d94357f
MD5 d9cac8c8458106b6eb028958b7960cb3
BLAKE2b-256 d4f738e29dd26b3a2def0c7d726c924108b7dd8279303cd95e34b53528c73d1f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.16-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2e079d68d6d7685eedef788d643d78ec77e2ae9382fc136eca95f4fadd7071b4
MD5 61c612a5622a2ab7f4fdc23126d5437c
BLAKE2b-256 434e9b60fd5b4b06b5b1a731cc1b5d4fd22c99ec156c3a113d71d42bc7070f63

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: real_regex-2026.7.16-cp310-abi3-win32.whl
  • Upload date:
  • Size: 473.4 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.16-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 cbf6f02c4ccc5fdafcc1d266313bb02f99f5c8b5363ca2d3cd1cc930293186b1
MD5 43a0ecb4771bbfa6ffdc2862ce0b2b0a
BLAKE2b-256 652763a5517876810996ebf0d966f5e01c83bc3a118c326f9c64a2a48ea615b7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.16-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 09fd5f9b6217bc68416dae678a224f3db0088e3e71f735e7cf9119cfc1d08418
MD5 ecafcafe4ad251012fe846836737851a
BLAKE2b-256 b867a1406b2809b6b2efe50968d40b8e19fde001fa5b1ba8d0285b6c8d3e2fa2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.16-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 232499b269550276bdf7508bf10c2c570c71a847b3b07f532ba5c4314d30a5fa
MD5 641f662e7ad06921944b86f6dbdc9e53
BLAKE2b-256 365c22dc53c414e7fa624eabe9585a1427cfe58b67fbd65d69e80efa47390835

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.16-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 75302c742abf7df66c839573ad1005ed429a2bc5a4b83d24cd27a1e74fe00c1a
MD5 713a8864f1c18dd2b8aba686d6543deb
BLAKE2b-256 79967ce194bb1b9c5e3d1a7b2d30c71e93f95f427c2de325dcab991376801d50

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.16-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 fed75e47fca3274520ee68abbaeab8c23195b358dfc8891bdbc95effc770b1ea
MD5 28aadb70d552f23fd87eba2e86b991c4
BLAKE2b-256 2f17c3f3cb21bb8befe99e3b8b5cbd5ce43ea7d2cdc4f02c11afd7749f751436

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.16-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 706f397a309238c8982bcdefb288c32246a8f034509ef73d5f9cec4b23c5833a
MD5 59bc7e78410437bda402302570eb9e5f
BLAKE2b-256 fc324d5f3ae54a6bd1da146a0060992fc2c557dfe8011b2a0078cfbd2ec10e93

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.16-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8e5d8ad75a33db97497dbf29b4334ba2ccd3b6fd47a988f924ebe47a8a9f1348
MD5 0ed74182996f890fe676eda62cf4c8b2
BLAKE2b-256 85933a40e6f6933752fa2b56808fccd71d0621685adfb17c5d4fcaa9a7e9c1b7

See more details on using hashes here.

Provenance

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