Generate regex for numerical ranges
Project description
Range-Ex
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
1234orabc25def53, so you may want to wrap it in^and$to match the whole string or\b...\bto 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d41595127c20019dd511fc3224f53cac89fb0945749e29a6d76e811e39897847
|
|
| MD5 |
cc04aa84a96d84546c01e49dab257604
|
|
| BLAKE2b-256 |
7318da03b2810a40d96a88a517c6cb1dc5d23832dec3add9aadc064d1158688a
|
Provenance
The following attestation bundles were made for range_ex-0.0.2.tar.gz:
Publisher:
python-publish.yml on nielstron/range-ex
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
range_ex-0.0.2.tar.gz -
Subject digest:
d41595127c20019dd511fc3224f53cac89fb0945749e29a6d76e811e39897847 - Sigstore transparency entry: 211262173
- Sigstore integration time:
-
Permalink:
nielstron/range-ex@c9f6796848c1c54092bfb59946543464aa08a8f6 -
Branch / Tag:
refs/tags/0.0.2 - Owner: https://github.com/nielstron
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c9f6796848c1c54092bfb59946543464aa08a8f6 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b47c5523c494f8838d541b224427a9ccc89991b9b28f378deaca72206f594a1e
|
|
| MD5 |
b60feafa1e6afdfb1471e20d4a940de4
|
|
| BLAKE2b-256 |
6dd2bf626b5ca57edeeea2b6814dc9abc0419311c623bcb49b85869dd93ed815
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
range_ex-0.0.2-py3-none-any.whl -
Subject digest:
b47c5523c494f8838d541b224427a9ccc89991b9b28f378deaca72206f594a1e - Sigstore transparency entry: 211262174
- Sigstore integration time:
-
Permalink:
nielstron/range-ex@c9f6796848c1c54092bfb59946543464aa08a8f6 -
Branch / Tag:
refs/tags/0.0.2 - Owner: https://github.com/nielstron
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c9f6796848c1c54092bfb59946543464aa08a8f6 -
Trigger Event:
push
-
Statement type: