Welcome to rewrapped’s documentation!

https://travis-ci.org/hansi-b/rewrapped.svg?branch=master https://codecov.io/gh/hansi-b/rewrapped/branch/master/graph/badge.svg https://badge.fury.io/py/rewrapped.svg

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

To do so,

  1. subclass from ReWrap,
  2. put the regular expression in the special matchOn class field, and
  3. add match fields to refer to match results.

A simple example for a ReWrap class with two match fields:

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

ReWrap subclasses provide the usual bag of regular expression search methods (search, match, etc.) as class methods, and return instances of the respective class which evaluate the match fields from matched results. E.g., the Inventory defined above would map the first match group as an integer to the field count, and the second to the string field item:

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

Indices and tables

Kudos

… go to https://daler.github.io/sphinxdoc-test/includeme.html and https://gist.github.com/brantfaircloth/791759 for their detailed accounts on how to get the sphinx documentation into the gh-pages branch.