Skip to main content

Readable regular expressions in Python

Project description

🦄 Magic RegEx

Readable Regular Expressions for Python

Stable Version Python Versions License Downloads

  1. Runtime is ultra-minimal
  2. Compiles to pure RegEx
  3. Automatically typed capture groups
  4. Natural language syntax

This library is a port of the magic-regexp JavaScript module by Daniel Roe.

Quickstart

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('daniel@roe.uk lore ipsum thomas@wollmann.de') 
# Result: ['daniel@roe.uk', 'thomas@wollmann.de']

Documentation

Up to now, this module is compatible with magic-regexp's documentation.

Contribute

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

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

magicregex-0.1.3.tar.gz (8.3 kB view hashes)

Uploaded Source

Built Distribution

magicregex-0.1.3-py3-none-any.whl (8.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page