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.2.tar.gz (6.5 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.2-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for range_ex-0.0.2.tar.gz
Algorithm Hash digest
SHA256 d41595127c20019dd511fc3224f53cac89fb0945749e29a6d76e811e39897847
MD5 cc04aa84a96d84546c01e49dab257604
BLAKE2b-256 7318da03b2810a40d96a88a517c6cb1dc5d23832dec3add9aadc064d1158688a

See more details on using hashes here.

Provenance

The following attestation bundles were made for range_ex-0.0.2.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.2-py3-none-any.whl.

File metadata

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

File hashes

Hashes for range_ex-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b47c5523c494f8838d541b224427a9ccc89991b9b28f378deaca72206f594a1e
MD5 b60feafa1e6afdfb1471e20d4a940de4
BLAKE2b-256 6dd2bf626b5ca57edeeea2b6814dc9abc0419311c623bcb49b85869dd93ed815

See more details on using hashes here.

Provenance

The following attestation bundles were made for range_ex-0.0.2-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