rewrapped

Class wrappers for regular expressions with proper fields for match groups.


License
MIT
Install
pip install rewrapped==0.5.0

Documentation

rewrapped

https://travis-ci.org/hansi-b/rewrapped.svg?branch=master

For the time being, more documentation is at this project's github pages.

rewrapped lets you wrap your regular expressions in classes with match groups flexibly mapped to named fields.

A simple example:

from rewrapped import ReWrap, matched
class Inventory(ReWrap):
    matchOn = "([0-9]+)\s+(\S+)"
    count = matched.g1.asInt
    item = matched.g2

This will yield match results which map the first match field to the integer count, and the second to the string field item:

>>> i = Inventory.search("there are 45 oranges left")
>>> i.count
45
>>> i.item
'oranges'
>>>