Skip to main content

Really, really easy regular expressions for python.

Project description

Easy does it!

Easy does it!

easy-expressions Build Status

The world’s most gangsta regular expressions library.

It turns this..

regex = re.compile(r'(?:(?:\$){1,1})(?:(?:(?:\d)){1,})(?:(?:\.){1,1})(?:\d)(?:\d)')

into this!

from easy_expressions import Easy

easy = Easy() /
  .find("$") /
  .min(1).digits() /
  .then(".") /
  .digit() /
  .digit()

regex = easy.getRegex()
regex.findall("$10.00");

About

easy-expressions is a python regular expressions library with a Python for Humans philosophy. Rather than having to remember the complex regular expressions syntax, easy-expressions allows you to write complicated regular expressions in natural English, so you’ll get your pattern matches right the first time without any headache.

Installation

pip install easy-expressions

Examples

Searching for dollar amounts

from easy_expressions import Easy

easy = Easy() /
  .find("$") /
  .min(1).digits() /
  .then(".") /
  .digit() /
  .digit()

regex.test("$10.00"); # True
regex.test("$XX.YZ"); # False

Searching for Credit Cards

easy = Easy() \
        .startOfLine() \
        .exactly(4).digits() \
        .then('-') \
        .exactly(4).digits() \
        .then('-') \
        .exactly(4).digits() \
        .then('-') \
        .exactly(4).digits()

input_s = "Hey Joe! The credit card number for the invoice is 4444-5555-6666-7777. Thanks!"
easy.test(input_s) # True

input_s = "Hey Joe! The credit card number for the invoice is 1-2-3-4. Thanks!"
easy.test(input_s) # False

Inspiration

Regexes are hard when they should be easy.

I had this idea while watching Straight Outta Compton. Turns out [@thebinarysearchtree](https://github.com/thebinarysearchtree/) had already implemented it in JS, so this is essentially a port of that.

Contributing

This software is still quite young and I’m certain there are still bugs in it. If you find bugs or want new features included, please create a new Issue and send a pull request, along with an accompanying test. Thanks!

Other Easy Projects

If you like easy things, you may also enjoy:

License

MIT, 2015.

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

easy-expressions-0.1.1.tar.gz (4.9 kB view details)

Uploaded Source

File details

Details for the file easy-expressions-0.1.1.tar.gz.

File metadata

File hashes

Hashes for easy-expressions-0.1.1.tar.gz
Algorithm Hash digest
SHA256 daec75889a1a86314f7bd2d1f76a62ed075acc5692236a37c818d2df985c9913
MD5 694ff75b897d1a168470a637b87bda67
BLAKE2b-256 dc4f2c676b98841ad01c66c122b2d6048f5ff21354edeed6b94a6fbe9a9891d7

See more details on using hashes here.

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