Readable Regular Expressions for Python
- Runtime is ultra-minimal
- Compiles to pure RegEx
- Automatically typed capture groups
- Natural language syntax
This library is a port of the magic-regexp JavaScript module by Daniel Roe.
First, install magicregex
by
pip install magicregex
Second, find e-mails in text by
import magicregex as mre
reg = mre.createRegEx(
mre.exactly(
mre.letter.TimesAtLeast(1)
.And(mre.exactly('@'))
.And(mre.letter.TimesAtLeast(1))
.And(mre.exactly('.'))
.And(mre.letter.TimesAtLeast(2))
)
)
reg.findall('[email protected] lore ipsum [email protected]')
# Result: ['[email protected]', '[email protected]']
Up to now, this module is compatible with magic-regexp's documentation.
Made with ❤️. If you want to support:
- Clone this repository
- Install dependencies using
poetry install --with dev
- Run tests using
pytest
- Run code checks using
pre-commit run