Skip to main content

Maker Regular Expressions

Project description

Maker Regular Expression

PyPI

This is a simple package to make regular expressions in Python.

pip install mre

Documentation

Examples

from mre import Regex, Group

rgx_one = Regex("Hello world")  # Hello world
rgx_two = Regex("Hello", " world")  # Hello world
rgx_three = Regex("Hello") + " " + Regex("world")  # Hello world
rgx_four = Regex('<', Group('h[1-6]'), '>')  # <(h[1-6])>
rgx_five = Regex('<', Regex.SLASH, 1, '>')  # <\/\1>
from mre import Set
from mre.helper import Range

# All digits
digits = Set(Range(0, 9))
# Add comment
digits = digits.comment('Get all digits')

# Output: [0-9](?#Get all digits)
from mre import Regex, Set, Comment

# All digits
digits = Set(Regex("0-9"))
# CEP comment
cep_comment = Comment('Get zip code Brazil on input')
# CEP regex
rgx_cep = Regex(
    digits.quantifier(5),
    Regex("-").quantifier(0, 1),
    digits.quantifier(3),
    cep_comment
)

# Output: [0-9]{5}-?[0-9]{3}(?#Get zip code Brazil on input)

Tests

To test the package just run the following command:

# (first time only) Build the Docker image
make build

# Run tests
make test

# Run tests and check coverage
make test-coverage

Contributing

Contributions are more than welcome. Fork, improve and make a pull request. For bugs, ideas for improvement or other, please create an issue.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

mre-0.12.0.tar.gz (5.9 kB view hashes)

Uploaded Source

Built Distribution

mre-0.12.0-py3-none-any.whl (7.9 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