Skip to main content

Generate regex for numerical ranges

Project description

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

Pass a minimum and maximum value to the range_regex function to generate a regex that matches numbers in that range. The range is inclusive, meaning both the minimum and maximum values are included in the regex.

Supports integer numbers and negative range.

from range_ex import range_regex

regex1 = range_regex(5,89)
# ([5-9]|[2-7][0-9]|1[0-9]|8[0-9])

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

Note: This will still find matches in strings like 1234 or abc25def53, so you may want to wrap it in ^ and $ to match the whole string or \b...\b to ensure word boundaries are matched.

If you only pass one of the two arguments, the other will be set to None, which means it will not be constrained. In this case, the regex will match any number that is greater than or equal to the minimum or less than or equal to the maximum.

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

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

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.

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

range_ex-0.0.3.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

range_ex-0.0.3-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file range_ex-0.0.3.tar.gz.

File metadata

  • Download URL: range_ex-0.0.3.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for range_ex-0.0.3.tar.gz
Algorithm Hash digest
SHA256 21969c941fb52fb1e471d5ac150bd13b556e7019108c5bb8269230846facee4f
MD5 ebb7ba700ee9cac0bf2ae9b39a3c7a1d
BLAKE2b-256 44dcc851ce1e3b75ce543d6667a64b59e660f5bd866f653f47896af9baafd348

See more details on using hashes here.

Provenance

The following attestation bundles were made for range_ex-0.0.3.tar.gz:

Publisher: python-publish.yml on nielstron/range-ex

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file range_ex-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: range_ex-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for range_ex-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 af3a460e60a628f19632116cc0851f627d143d239c737a9271e2e1414aa8a179
MD5 52deb5a79e34ff83e62ea22fd99b7ed2
BLAKE2b-256 db4bb04d6998d46722e2980e2ebc286db6731fb8a069d3ee15c87e32e5fe5cce

See more details on using hashes here.

Provenance

The following attestation bundles were made for range_ex-0.0.3-py3-none-any.whl:

Publisher: python-publish.yml on nielstron/range-ex

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