<?xml version="1.0" encoding="UTF-8" ?>
<rdf:RDF xmlns="http://usefulinc.com/ns/doap#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><Project><name>hachoir-regex</name>
<shortdesc>Manipulation of regular expressions (regex)</shortdesc>
<description>Hachoir regex
=============

hachoir-regex is a Python library for regular expression (regex or regexp)
manupulation. You can use a|b (or) and a+b (and) operators. Expressions are
optimized during the construction: merge ranges, simplify repetitions, etc.
It also contains a class for pattern matching allowing to search multiple
strings and regex at the same time.

Website: http://bitbucket.org/haypo/hachoir/wiki/hachoir-regex

Changelog
=========

Version 1.0.3

 * Raise SyntaxError on unsupported escape character
 * Two dot atoms are always equals

Version 1.0.2 (2007-07-12)

 * Refix PatternMatching without any pattern

Version 1.0.1 (2007-06-28)

 * Fix PatternMatching without any pattern

Version 1.0 (2007-06-28)

 * First public version

Regex examples
==============

Regex are optimized during their creation:

   &gt;&gt;&gt; from hachoir_regex import parse, createRange, createString
   &gt;&gt;&gt; createString("bike") + createString("motor")
   &lt;RegexString 'bikemotor'&gt;
   &gt;&gt;&gt; parse('(foo|fooo|foot|football)')
   &lt;RegexAnd 'foo(|[ot]|tball)'&gt;

Create character range:

   &gt;&gt;&gt; regex = createString("1") | createString("3")
   &gt;&gt;&gt; regex
   &lt;RegexRange '[13]'&gt;
   &gt;&gt;&gt; regex |= createRange("2", "4")
   &gt;&gt;&gt; regex
   &lt;RegexRange '[1-4]'&gt;

As you can see, you can use classic "a|b" (or) and "a+b" (and)
Python operators. Example of regular expressions using repetition:

   &gt;&gt;&gt; parse("(a{2,}){3,4}")
   &lt;RegexRepeat 'a{6,}'&gt;
   &gt;&gt;&gt; parse("(a*|b)*")
   &lt;RegexRepeat '[ab]*'&gt;
   &gt;&gt;&gt; parse("(a*|b|){4,5}")
   &lt;RegexRepeat '(a+|b){0,5}'&gt;

Compute minimum/maximum matched pattern:

   &gt;&gt;&gt; r=parse('(cat|horse)')
   &gt;&gt;&gt; r.minLength(), r.maxLength()
   (3, 5)
   &gt;&gt;&gt; r=parse('(a{2,}|b+)')
   &gt;&gt;&gt; r.minLength(), r.maxLength()
   (1, None)

Pattern maching
===============

Use PatternMaching if you would like to find many strings or regex in a string.
Use addString() and addRegex() to add your patterns.

    &gt;&gt;&gt; from hachoir_regex import PatternMatching
    &gt;&gt;&gt; p = PatternMatching()
    &gt;&gt;&gt; p.addString("a")
    &gt;&gt;&gt; p.addString("b")
    &gt;&gt;&gt; p.addRegex("[cd]")

And then use search() to find all patterns:

    &gt;&gt;&gt; for start, end, item in p.search("a b c d"):
    ...    print "%s..%s: %s" % (start, end, item)
    ...
    0..1: a
    2..3: b
    4..5: [cd]
    6..7: [cd]

You can also attach an objet to a pattern with 'user' (user data) argument:

    &gt;&gt;&gt; p = PatternMatching()
    &gt;&gt;&gt; p.addString("un", 1)
    &gt;&gt;&gt; p.addString("deux", 2)
    &gt;&gt;&gt; for start, end, item in p.search("un deux"):
    ...    print "%r at %s: user=%r" % (item, start, item.user)
    ...
    &lt;StringPattern 'un'&gt; at 0: user=1
    &lt;StringPattern 'deux'&gt; at 3: user=2


Installation
============

With distutils:

   sudo ./setup.py install

Or using setuptools:

   sudo ./setup.py --setuptools install</description>
<download-page>http://bitbucket.org/haypo/hachoir/wiki/hachoir-regex</download-page>
<homepage rdf:resource="http://bitbucket.org/haypo/hachoir/wiki/hachoir-regex" />
<maintainer><foaf:Person><foaf:name>Victor Stinner</foaf:name>
</foaf:Person></maintainer>
<release><Version><revision>1.0.3</revision></Version></release>
</Project></rdf:RDF>