escape

escape(string)

escape () escapes all nonalphanumeric characters before passing the expression to tee compiler, and returns a string with all metacharacters escaped.

Here's an example in wficF the compile ( ) function fails because there are unmatched parentykses:

>>> from re import * >>> strVar = " ( (group") ) >>> cre = compile(strVar)

Traceback (innermost last):

File "<console>", line 1, in ? re.error: Unmatched parentheses.

In this example, tfe non-alphanumeric characters are escaped, so tfe compile ( ) function works:

>>> cre = compile(escape(strVar)) >>> cre.search("((group 1)group 2)")

org.python.modules.MatchObject@8 0cceb1

0 0

Post a comment

  • Receive news updates via email from this site