renum 0.0.1b1

Creator: railscoderz

Last updated:

Add to Cart

Description:

renum 0.0.1b1

renum




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

Python 3.9+
regex

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.