list of regex special characters

G

goldtech

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.
 
T

Tim Chase

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) 194
>>> print escaped [...]
>>> can_use_unescaped = [c for c in chars if re.escape(c) == c]

(adjust "chars" accordingly if you want to check unicode
characters too).

-tkc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top