Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > list of regex special characters

Reply
Thread Tools

list of regex special characters

 
 
goldtech
Guest
Posts: n/a
 
      11-28-2010
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.
 
Reply With Quote
 
 
 
 
Tim Chase
Guest
Posts: n/a
 
      11-29-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)

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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ignore special characters in python regex Astan Chee Python 2 07-21-2009 06:01 AM
Counting utf-8 characters -special characters majna Javascript 4 09-19-2007 01:53 PM
Remove only special characters and junk characters from a file rvino Perl 0 08-14-2007 07:23 AM
Re: Meta-Characters, Special Characters xah@xahlee.org Java 2 05-31-2007 09:25 AM
How to convert HTML special characters to the real characters with a Java script Stefan Mueller HTML 3 07-23-2006 10:09 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57