list of regex special characters

Discussion in 'Python' started by goldtech, Nov 28, 2010.

  1. goldtech

    goldtech Guest

    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.
     
    goldtech, Nov 28, 2010
    #1
    1. Advertising

  2. goldtech

    Tim Chase Guest

    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
     
    Tim Chase, Nov 29, 2010
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Mueller
    Replies:
    3
    Views:
    33,043
    Stefan Mueller
    Jul 23, 2006
  2. Replies:
    2
    Views:
    1,095
    Ingo Menger
    May 31, 2007
  3. rvino
    Replies:
    0
    Views:
    4,660
    rvino
    Aug 14, 2007
  4. Astan Chee
    Replies:
    2
    Views:
    987
    John Machin
    Jul 21, 2009
  5. majna
    Replies:
    4
    Views:
    676
    Thomas 'PointedEars' Lahn
    Sep 19, 2007
Loading...

Share This Page