Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Regular expressions for the 21st century. Match any data type.

Project description

Non-String Regular Expressions

Build Status

NSRE (Non-String Regular Expressions) is a new spin at regular expressions. It's really abstract, even compared to regular expressions as you know them, but it's also pretty powerful for some uses.

Here's the twist: what if regular expressions could, instead of matching just character strings, match any sequence of anything?

from nsre import *

re = RegExp.from_ast(seq('hello, ') + (seq('foo') | seq('bar')))
assert re.match('hello, foo')

The main goal here is matching NLU grammars when there is several possible interpretations of a single word, however there is a lot of other things that you could do. You just need to understand what NSRE is and apply it to something.

Note — This is inspired by this article from Russ Cox, which explains how Thompson NFA work, except that I needed to add some features and then the implementation is much less elegant because I actually don't know what I'm doing. But it seems to be working.

Documentation

Documentation is there

Licence

This library is provided under the terms of the WTFPL.

If you find it useful, you can have a look at the contributors page to know who helped.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for nsre, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size nsre-0.2.0-py3-none-any.whl (13.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size nsre-0.2.0.tar.gz (13.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page