Skip to main content

Range-Ex

Tests & QA Coverage Status PyPI version PyPI - Python Version PyPI - Status

This tool builds a regular expression for a numerical range.

Installation

pip install range-ex

Usage

Use range_regex for integer ranges and float_range_regex for decimal ranges.

Integer ranges (range_regex)

range_regex matches only integers (including negatives). The range is inclusive on both ends.

from range_ex import range_regex

regex1 = range_regex(5, 89)
# (?:[5-9]|[2-7]\d|1\d|8\d)

regex2 = range_regex(-65, 12)
# (?:\-[1-9]|\-[2-5]\d|\-1\d|\-6[0-5]|\d|1[0-2])

If you pass only one bound, the other is unbounded:

regex3 = range_regex(minimum=5)
# (?:[5-9]|[1-9]\d(?:\d)*)

regex4 = range_regex(maximum=89)
# (?:\-[1-9](?:\d)*|\d|[2-7]\d|1\d|8\d)

regex5 = range_regex()
# (?:\-[1-9](?:\d)*|[1-9](?:\d)*|0)

Decimal ranges (float_range_regex)

float_range_regex accepts int, float, Decimal, and decimal-parseable str bounds.

from range_ex import float_range_regex

regex6 = float_range_regex(0.5, 1.5, strict=True)
# (?:(?:0)?\.[5-9](?:\d)*|1\.[0-5](?:\d)*)

regex7 = float_range_regex(0.5, 1.5, strict=False)
# (?:1|(?:0)?\.[5-9](?:\d)*|1\.[0-5](?:\d)*)

regex8 = float_range_regex(maximum="1.5", strict=True)
# (?:\-[1-9](?:\d)*\.\d(?:\d)*|(?:0)?\.\d(?:\d)*|1\.[0-5](?:\d)*)

regex9 = float_range_regex(strict=True)
# (?:(?:\-)?(?:0|[1-9](?:\d)*)\.\d(?:\d)*|(?:\-)?(?:0|[1-9](?:\d)*)\.|(?:\-)?\.\d(?:\d)*)

Rendering options

Both APIs support capturing=True to emit capturing groups ((...)) instead of non-capturing groups ((?:...)):

range_regex(-65, 12, capturing=True)
# (\-[1-9]|\-[2-5]\d|\-1\d|\-6[0-5]|\d|1[0-2])

Note: Generated regexes can still match inside larger strings (for example, inside abc25def). Use anchors like ^...$ if you need whole-string matches.

Contributing

Contributions are very welcome. Please open an issue or a pull request if you have any suggestions or improvements.

To test your changes, run the following command:

pytest -n 5

Acknowledgements

This project is based on regex_engine. Feel free to check it out.

Metadata

Release files for range-ex 0.0.5

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

Source distribution (sdist)

Source distribution for range-ex 0.0.5
File Size Uploaded
range_ex-0.0.5.tar.gz 14.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for range-ex 0.0.5
File Interpreter ABI Platform
range_ex-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 25.9 kB

Release files / range_ex-0.0.5.tar.gz

Download URL range_ex-0.0.5.tar.gz
Size 14.6 kB
Tags Source
SHA-256 checksum
How to use checksums
01e9b9c4d74891ee97e89de81f06b2a6ff8f3617293cf20858bf7b89f9647542
BLAKE2b-256 checksum
How to use checksums
44882d191f3d0b36d8b918d00b1d95219c3bd4a567d51fbae951e0788f83e89c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 10, 2026.

Transparency log

Release files / range_ex-0.0.5-py3-none-any.whl

Download URL range_ex-0.0.5-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9bd2c590aa7b9350bc3e1f352229290b0e9986068940073eb25a441e5eb4134f
BLAKE2b-256 checksum
How to use checksums
1cec09ea712808d08a0d3963942201631d8f93f0e824bab07eb8887320f0a8f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 10, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.5 This release

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