A small package to convert verbose regex patterns to simple regex patterns.
Project description
Regex Cleaner
This is a simple python package that can be used to clean a verbose regex pattern of the comments and new lines and return the basic underlying pattern.
Installation
python -m pip install regex-cleaner
Usage
To clean a regex pattern, simply pass the verbose pattern string to the function clean_regex.
from regex_cleaner import clean_regex
pattern = r"""
\w\d{3} # Matches any letter followed by 3 digits.
"""
cleaned_regex = clean_regex(pattern)
print(cleaned_regex)
\w\d{3}
It should be noted that the pattern is cleaned by removing all comments from the string, then removing any whitespace left in the pattern. This means that if you are using whitespace to represent space characters in your pattern they will be trimmed out.
import regex_cleaner
pattern = r"""
\w* # Any letter repeated zero or more times.
[. ] # Full stop followed by a space.
"""
cleaned_pattern = regex_cleaner.clean_regex(pattern)
print(cleaned_pattern)
\w*[.]
Testing
Tests can be run using pytest or tox. To test, clone down the repository and from the root of the repository do either
python -m pytest
or
python -m tox
Project details
Release history Release notifications | RSS feed
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 regex_cleaner-1.0.2.tar.gz.
File metadata
- Download URL: regex_cleaner-1.0.2.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7daff53a86c3c79c03e1cf0785faa1bd8fe589a7660df02254d33b847bb217b3
|
|
| MD5 |
05d33d1d7d4b089c8ef7f74b0f954f7c
|
|
| BLAKE2b-256 |
f8eeeefc975ffa9d33b1e2e79156a9204d04898d7f8f06792cb07dfe3b5af5fa
|
File details
Details for the file regex_cleaner-1.0.2-py3-none-any.whl.
File metadata
- Download URL: regex_cleaner-1.0.2-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e223e292667af9fb47171fc0aba5c6f08f784c8a1e2b701c0da9c1becb4423f2
|
|
| MD5 |
1e8d88b5b350d58823bc493c0012b0bd
|
|
| BLAKE2b-256 |
adad99a9c50a68fe43b9fb1ec0518d969836315b4d14950af5793ea2c30b8183
|