Skip to main content

Object-Oriented Regular Expressions

Project description

OORE (Object oriented regular expressions) is a python library that attempts to provide an object oriented layer above the re standard library.

The idea behind this project is to enable users to create and combine regular expressions programmatically. The re module which is a more or less simple wrapper over an underlying C library doesn’t provide any interface that truly makes this possible, which means that especially complex regular expressions need to be generated by concatenating strings.

This means that dealing with such code is annoying, difficult, and error-prone.

To give you an example, this is how you would create a regular expression that matches a Unicode Language Identifier:

from oore import r

digit = r(u'[0-9]')
alpha = r(u'[A-Za-z')
alphanum = r(u'[0-9A-Za-z]')
unicode_variant_subtag = alphanum[5, 8] | (digit + alphanum[3])
unicode_region_subtag = alpha[2] | digit[3]
unicode_script_subtag = alpha[4]
unicode_language_subtag = alpha[2, 8]
sep = r(u'[-_]')

unicode_language_id = r(u'root') | (
    unicode_language_subtag +
    (sep + unicode_script_subtag)[0, 1] +
    (sep + unicode_region_subtag)[0, 1] +
    (sep + unicode_variant_subtag)[0, ...]
)

This can now be used like a re.RegexObject, to get a re.MatchObject you simply use the .match() method:

match = unicode_language_id.match('de-DE')

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

oore-0.2.1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

oore-0.2.1-py2.py3-none-any.whl (4.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file oore-0.2.1.tar.gz.

File metadata

  • Download URL: oore-0.2.1.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for oore-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9d19c13f10edf0f1889bc0a1cbdef45e29f97dd60594e012e058776242f8c160
MD5 74f0e0dae9148821c3ffccef7b444e59
BLAKE2b-256 7ebf7a71d20df36ae0f697c0f9ddbee6e55b8af8338422598b28b15193ee4091

See more details on using hashes here.

File details

Details for the file oore-0.2.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for oore-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 35f8b0da083f30ce53037c6b9eb6857b724dd904b745d14a2e48a8555c73934d
MD5 6921b2ba0ba89b9cd8312d3f06091126
BLAKE2b-256 b3c5717358e6cc8ec4168cbae1fb36c5656ed19958da3cb8c19e2eaaf04fb4cb

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