Skip to main content

Replus

PyPI Python versions CI codecov Documentation Status License: MIT Ruff

Template-based regular expression management, powered by the regex library.

Define regex fragments as named template keys, compose them with {{placeholders}}, and query matches through nested, named Match/Group objects — instead of maintaining one unreadable 400-character pattern.

  • Full documentation
  • Fully typed, zero-magic, 100% test coverage; the only runtime dependency is regex.

Installation

uv add replus
# or
pip install replus

Requires Python 3.11+.

Quickstart

The engine loads pattern templates from *.json files in a directory (or a plain dict). Every key defines a reusable fragment; only the patterns under $PATTERNS are matched at runtime.

patterns/date.json:

{
  "day": ["3[01]", "[12][0-9]", "0?[1-9]"],
  "month": ["0?[1-9]", "1[012]"],
  "year": ["\\d{4}"],
  "date": ["{{day}}/{{month}}/{{year}}", "{{year}}-{{month}}-{{day}}"],
  "$PATTERNS": ["{{date}}"]
}

builds and compiles to:

(?P<date_0>(?P<day_0>3[01]|[12][0-9]|0?[1-9])/(?P<month_0>0?[1-9]|1[012])/(?P<year_0>\d{4})|(?P<year_1>\d{4})-(?P<month_1>0?[1-9]|1[012])-(?P<day_1>3[01]|[12][0-9]|0?[1-9]))

Match and query by template key — the engine resolves which numbered alternative actually matched:

from replus import Replus

engine = Replus("patterns")

for match in engine.parse("Look at this date: 1970-12-25"):
    print(repr(match))
    # <[Match date] span(19, 29): 1970-12-25>

    date = match.group("date")
    print(repr(date.group("day")))    # <Group day_1 span(27, 29) @0: '25'>
    print(repr(date.group("month")))  # <Group month_1 span(24, 26) @0: '12'>
    print(repr(date.group("year")))   # <Group year_1 span(19, 23) @0: '1970'>

    print(match.json(indent=2))       # full nested serialization

Filter by pattern type (the template's file stem), or take the raw lazy stream:

engine.parse(text, filters=["date"])   # only date patterns
engine.parse(text, exclude=["cities"]) # everything but cities
engine.search(text)                    # first match or None
engine.finditer(text)                  # lazy, unpurged iterator

Rewrite captured groups in place — e.g. to fix OCR errors only inside matches, with a literal string or a callable receiving the Group:

engine.sub("ID 1809900 and 1809900", {"prefix": "l"})
# 'ID l809900 and l809900'
engine.sub(text, {"prefix": lambda g: g.value.replace("1", "l")})

There's more: backreferences ({{#key}}, {{#key@2}}), unnamed/atomic groups and lookarounds ({{?:key}}, {{?>key}}, {{?=key}}, …), repeated captures (group.reps()), whitespace-noise injection, and overlap purging. See the template syntax reference.

Development

git clone https://github.com/biagiodistefano/replus.git
cd replus
uv sync --all-groups

uv run pytest --cov=replus   # tests (coverage gate: 100%)
uv run ruff check .          # lint
uv run ruff format .         # format
uv run ty check              # type check
uv run sphinx-build -b html docs docs/_build  # docs

License

MIT © Biagio Distefano

Metadata

Release files for replus 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for replus 1.0.0
File Size Uploaded
replus-1.0.0.tar.gz 12.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for replus 1.0.0
File Interpreter ABI Platform
replus-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 28.3 kB

Release files / replus-1.0.0.tar.gz

Download URL replus-1.0.0.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1986c0825f97beffc3eed80b5061cb38da8889a3b420004770eb4a8db505e1dc
BLAKE2b-256 checksum
How to use checksums
1ea29effa892e9cbfcd6a6c60b9ccb1b96872eda82b223d75e28fc4eaf74c084
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.

Transparency log

Release files / replus-1.0.0-py3-none-any.whl

Download URL replus-1.0.0-py3-none-any.whl
Size 15.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1bd6e9d94b9bf7e73cf98a1fe0361c940c951925e4d1f171c6da3cd09183040e
BLAKE2b-256 checksum
How to use checksums
b1a8221f7f697f4c180b806b5e66c61d7afb4a7903b6f122237335dba932c69c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.3.0

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page