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.20.tar.gz (222.6 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.20-cp310-abi3-win_amd64.whl (492.7 kB view details)

Uploaded CPython 3.10+Windows x86-64

real_regex-2026.7.20-cp310-abi3-win32.whl (474.0 kB view details)

Uploaded CPython 3.10+Windows x86

real_regex-2026.7.20-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.20-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.20-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.20-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.20-cp310-abi3-macosx_11_0_arm64.whl (294.8 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

real_regex-2026.7.20-cp310-abi3-macosx_10_9_x86_64.whl (301.0 kB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: real_regex-2026.7.20.tar.gz
  • Upload date:
  • Size: 222.6 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.20.tar.gz
Algorithm Hash digest
SHA256 138079ddb60565f522876656ee6a147fc19e3723e70d6a6a4a3a56ddb7856764
MD5 d1de2dace175e7655e296e8399d4bf6d
BLAKE2b-256 4b81c0373b627e16b960e1ebb2dde4210c865448c4311e3ca62b63347a1b9bea

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.20-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 dc517d1525aa6fe83b88033140891b5091b2cd2c2d5e07a9de10abbeda0e4e60
MD5 4348a27398dea4dafd05ec087f513a46
BLAKE2b-256 d39d6bc8b6ca4b935937a3ca8034d887e625ec651dcd8712634e3d5d4505a5d3

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: real_regex-2026.7.20-cp310-abi3-win32.whl
  • Upload date:
  • Size: 474.0 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.20-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 e32e825a4c20c6d1be2d7235ce9ca215d5590f995b356687df6f3a156b4c9eb9
MD5 af57d59592677ab8153a9d22682f1cae
BLAKE2b-256 3a402ff4b6a1e8c367f16931436bf51fea18fccf6ad6e132edab9425bd56eba2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.20-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 09bb5c2c2c9c6cb8a20ffd5cf49a21a0da4ecf31c6a9af5e206be85d8682f543
MD5 fa0505ef3962b17fc3bf26074f1f82d6
BLAKE2b-256 d1548e4dd7801be9f78bb706271d95a4e9a443548bfeb86de190576497146171

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.20-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f14cb14bb2984eabea6edaf40ee8436032158497f1284ff9e11cbdc48eda1078
MD5 ae8c651b463c293873ce89f0c00f8b5a
BLAKE2b-256 23c9f4a987ff87ec76fec4edb8d58ed5b9b1095593f1ac5fb7e4f02695bf0bb0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.20-cp310-abi3-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 86c5810f006e1b76ee985485b88ab9a86400882d69914ed9c5638ff7172082a5
MD5 8c4999963b3c5490ec70fe2fd413b93d
BLAKE2b-256 8aab7a0087074c047dc880f4227d03f7c84f7a06d22cbeeadd88dcf16a055b08

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.20-cp310-abi3-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 55f01b7e0413d2bbcb97d3a392c78c7b9207684477b322d9fda9e955f53bba6c
MD5 a7bf4efa0f843db8487af9d56d5fadcb
BLAKE2b-256 b62f7b4b598d7e02ade725418e5cd45b52981b88760cf6bd30e94a5328da5221

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.20-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aee9561e5064f8a7326e3f9f417994ddc0e88b73178a3029526c8d3ff016ee96
MD5 1515d6d1f722ef0e62ac543994c59f3e
BLAKE2b-256 3009ecac0a615f01ee4cfb17e1db15d4bf36a2800e46951174b84f928ec44415

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for real_regex-2026.7.20-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 ea0c9eb1255b86d10c64a62a0cb9de2934b51eefee349da80cc07cebdd2b81eb
MD5 6ce64e752416050a7a150329961be8c8
BLAKE2b-256 e4cd289e83d68c052ac725286dc822e1ff419409bd264908a303e29049a1bcb4

See more details on using hashes here.

Provenance

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