Next / Previous / Contents / Shipman's homepage

5.28. Regex: Match a regular expression

pp.Regex(r, flags=0)

An instance of this class matches a regular expression expressed in the form expected by the Python re module. The argument r may be either a string containing a regular expression, or a compiled regular expression as an instance of re.RegexObject.

If the argument r is a string, you may provide a flags argument that will be passed to the re.match() function as its flags argument.

>>> r1 = '[a-e]+'
>>> pat1 = pp.Regex(r1)
>>> print pat1.parseString('aeebbaecd', parseAll=True)
>>> pat2 = pp.Regex(re.compile(r1))
>>> print pat2.parseString('dcbaee', parseAll=True)
>>> vowels = r'[aeiou]+'
>>> pat1 = pp.Regex(vowels)
>>> print pat1.parseString('eauoouEAUUO')
>>> pat2 = pp.Regex(vowels, flags=re.IGNORECASE)
>>> print pat2.parseString('eauoouEAUUO')