Skip to main content

Easily build Enum-like regular expression patterns

Project description

renum

pypi Licensed under the MIT License Ruff pre-commit.ci status

Regex Enum

A utility class for generating Enum-like regular expression patterns.

Installing

python3 -m pip install -U renum

Development version:

python3 -m pip install -U https://github.com/Zephyrkul/renum/archive/master.zip#egg=renum

Support

If you need help with using renum, find a bug, or have a feature request, feel free to file an issue.

Examples

Parsing from standard input:

import regex
from renum import renum


class Actions(renum, flags=regex.IGNORECASE):
    GO = r"go (?P<direction>north|south|east|west)"
    EXAMINE = r"examine (?P<item>[\w\s]+)"
    OPEN = r"open (?P<object>door|chest)"


if __name__ == "__main__":
    while True:
        line = input()
        if not line:
            break
        action = Actions.match(line)  # The renum class acts like a Pattern...
        if action is Actions.GO:
            print("You went %s" % action.group("direction"))  # and each entry acts like a Match
        elif action is Actions.EXAMINE:
            print("You take a closer look at %s. Looks grungy." % action.group("item"))
        elif action is Actions.OPEN:
            print("You tried to open the %s, but it was locked." % action.group("object"))
        else:
            print("Unknown action: %s" % line)

Troubleshooting a misbehaving renum:

>>> import regex
>>> from renum import renum
>>>
>>> class Bad(renum, flags=regex.IGNORECASE | regex.DEBUG):
...     GOOD = r"no (?:issues|problems) here"
...     BAD = r"whoops,\s(?P<missed something)"
...
regex.error: bad character in group name at position 29 in BAD
whoops,\s(?P<missed something)
                             ^

Requirements

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

renum-0.0.1b1.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

renum-0.0.1b1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file renum-0.0.1b1.tar.gz.

File metadata

  • Download URL: renum-0.0.1b1.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for renum-0.0.1b1.tar.gz
Algorithm Hash digest
SHA256 30c367de3f95f079210508d497b5224002337422ddb43ae4dd83a199b3c87df7
MD5 274df999631275cd411064a965a98b2a
BLAKE2b-256 c0af6808c4b073bcef563169ab389a1641ef87f10672bacc0663793bd98e80af

See more details on using hashes here.

File details

Details for the file renum-0.0.1b1-py3-none-any.whl.

File metadata

  • Download URL: renum-0.0.1b1-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for renum-0.0.1b1-py3-none-any.whl
Algorithm Hash digest
SHA256 e8610e2c1cecfc39cce56a58216a2fecf9c6d369dfe5addec8773ca9fac4e18b
MD5 92ff0db9d4a2df864691e514ee0712c6
BLAKE2b-256 d934390007ac148c9df3c63cb27351dad5a3b20f687b41aa448c03957c5bc5e6

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