list of regex special characters
python.list at tim.thechases.com
Mon Nov 29 01:23:46 CET 2010
On 11/28/2010 05:58 PM, goldtech wrote:
> I am looking for a list of special character in python regular
> expressions that need to be escaped if you want their literal meaning.
> I searched and can not find the list. Any help appreciated.
Trust the re module to tell you:
>>> import re
>>> chars = [chr(i) for i in range(0,256)]
>>> escaped = [c for c in chars if re.escape(c) != c]
>>> print len(escaped)
>>> print escaped
>>> can_use_unescaped = [c for c in chars if re.escape(c) == c]
(adjust "chars" accordingly if you want to check unicode
More information about the Python-list