Regular Expressions

Let’s first create the regex field.

>>> from z3c.schema.regex import Regex
>>> regex = Regex()

The regex field only allows compilable regular expressions.

>>> regex.validate(r'.*')
>>> regex.validate(r'^\s+$')

It does not validate regular expressions that do not compile.

>>> regex.validate('(i')
Traceback (most recent call last):
...
InvalidRegex: '(i', unbalanced parenthesis

When used to process input, only valid values are returned.

>>> regex.fromUnicode(u'.*')
'.*'
>>> regex.fromUnicode(u'(i')
Traceback (most recent call last):
...
InvalidRegex: '(i', unbalanced parenthesis

Reference

interface z3c.schema.regex.interfaces.IRegex[source]

Extends: zope.schema.interfaces.IASCIILine

Regular Expression field

exception z3c.schema.regex.interfaces.InvalidRegex[source]

Bases: zope.schema._bootstrapinterfaces.ValidationError

The specified regular expression is not valid.

class z3c.schema.regex.field.Regex(min_length=0, max_length=None, **kw)[source]

Bases: zope.schema._field.ASCIILine

Regex schema field.

Must be a compilable regular expression