
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
reagex
Advanced tools
The goal of reagex (from "readable regular expression")
is to suggest a way for writing complex regular expressions with
many capturing groups in a readable way.
At the moment, it contains just one very simple function
(called reagex) and an utility function, but any function
which could be useful for writing readable patterns is welcome.
Note: Publishing this ridiculously small project is an excuse to familiarize with python packaging, DevOps tools and the entire workflow behind the publication of an open-source project. The project template was generated using https://github.com/ionelmc/cookiecutter-pylibrary/ which is obviously an overkill for a "one-function-project".
The core function reagex is just a wrapper of str.format and it works
in the same way. See the example
.. code-block:: python
import re
from reagex import reagex
# A sloppy pattern for an italian address (just to show how it works)
pattern = reagex(
'{_address}, {postcode} {city} {province}',
# groups starting with "_" are non-capturing
_address = reagex(
'{street} {number}',
street = '(via|contrada|c/da|c[.]da|piazza|p[.]za|p[.]zza) [a-zA-Z]+',
number = 'snc|[0-9]+'
),
postcode = '[0-9]{5}',
city = '[A-Za-z]+',
province = '[A-Z]{2}'
)
matcher = re.compile(pattern)
match = matcher.fullmatch('via Roma 123, 12345 Napoli NA')
print(match.groupdict())
# prints:
# {'city': 'Napoli',
# 'number': '123',
# 'postcode': '12345',
# 'province': 'NA',
# 'street': 'via Roma'}
Groups starting by '_' are non-capturing. The rest are all named capturing
groups.
I think reagex is easier to write and to read:
then you provide a pattern for each group;
with re.VERBOSE you have to define the groups in the exact position they
must be matched: to get the high-level structure of the pattern you may need
to read multiple lines at the same indentation level::
pip install reagex
https://python-reagex.readthedocs.io/
Possible improvements:
make some meaningful use of the format_spec
in {group_name:format_spec}
add utility functions like repeated to help writing
common patterns in a readable way
To run all the tests::
tox
Note, to combine the coverage data from all the tox environments run:
.. list-table:: :widths: 10 90 :stub-columns: 1
- - Windows
- ::
set PYTEST_ADDOPTS=--cov-append
tox
- - Other
- ::
PYTEST_ADDOPTS=--cov-append tox
FAQs
Utility functions for writing readable regular expressions in a hierarchical way
We found that reagex demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.