4.3.1 Module Contents

The module defines two functions and a handful of constants.

convert( pattern[, syntax=None])
Convert a pattern representing a regex-stype regular expression into a re-style regular expression. The optional syntax parameter is a bitwise-or'd set of flags that control what constructs are converted. See below for a description of the various constants.

quote( s[, quote=None])
Convert a string object to a quoted string literal.

This is similar to repr but will return a "raw" string (r'...' or r"...") when the string contains backslashes, instead of doubling all backslashes. The resulting string does not always evaluate to the same string as the original; however it will do just the right thing when passed into re.compile().

The optional second argument forces the string quote; it must be a single character which is a valid Python string quote. Note that prior to Python 2.5 this would not accept triple-quoted string delimiters.

RE_NO_BK_PARENS
Suppress paren conversion. This should be omitted when converting sed-style or emacs-style regular expressions.

RE_NO_BK_VBAR
Suppress vertical bar conversion. This should be omitted when converting sed-style or emacs-style regular expressions.

RE_BK_PLUS_QM
Enable conversion of + and ? characters. This should be added to the syntax arg of convert when converting sed-style regular expressions and omitted when converting emacs-style regular expressions.

RE_NEWLINE_OR
When set, newline characters are replaced by |.
See About this document... for information on suggesting changes.