UNKNOWN
Project description
OORE
====
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, ...]
)
.. _Unicode Language Identifier: http://www.unicode.org/reports/tr35/#Unicode_language_identifier
This can now be used like a :class:`re.RegexObject`, to get a
:class:`re.MatchObject` you simply use the `.match()` method::
match = unicode_language_id.match('de-DE')
====
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, ...]
)
.. _Unicode Language Identifier: http://www.unicode.org/reports/tr35/#Unicode_language_identifier
This can now be used like a :class:`re.RegexObject`, to get a
:class:`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.1.0.tar.gz
(2.8 kB
view hashes)