re and escape character

Discussion in 'Python' started by Sinan Nalkaya, Sep 15, 2005.

  1. i re-format incoming messages like this,
    command = re.findall("^\002(.{2})\|.*\003$", response)[0]
    it works well but when response comes with escape characters , my
    command variable crashes,
    i cannot parse if response variable is like ,
    response = '\002AB|TIasdasdasd
    asdasdasd
    xzczxc
    qwewer
    werwer|\003'

    ps:there must be \002 at the start and \003 at the end.
    thanks.
     
    Sinan Nalkaya, Sep 15, 2005
    #1
    1. Advertisements

  2. Am Thu, 15 Sep 2005 14:36:38 +0300 schrieb Sinan Nalkaya:

    > i re-format incoming messages like this,
    > command = re.findall("^\002(.{2})\|.*\003$", response)[0]
    > it works well but when response comes with escape characters , my
    > command variable crashes,
    > i cannot parse if response variable is like ,
    > response = '\002AB|TIasdasdasd
    > asdasdasd
    > xzczxc
    > qwewer
    > werwer|\003'
    >
    > ps:there must be \002 at the start and \003 at the end.
    > thanks.


    Hi,

    I don't know what you mean with "escape characters".
    The dot does not match a newline. You have to use the
    re.DOTALL option if you want this.

    HTH,
    Thomas

    --
    Thomas G├╝ttler, http://www.thomas-guettler.de/
    E-Mail: guettli (*) thomas-guettler + de
    Spam Catcher:
     
    Thomas Guettler, Sep 15, 2005
    #2
    1. Advertisements

  3. Thomas Guettler wrote:

    >Am Thu, 15 Sep 2005 14:36:38 +0300 schrieb Sinan Nalkaya:
    >
    >
    >
    >>i re-format incoming messages like this,
    >>command = re.findall("^\002(.{2})\|.*\003$", response)[0]
    >>it works well but when response comes with escape characters , my
    >>command variable crashes,
    >>i cannot parse if response variable is like ,
    >>response = '\002AB|TIasdasdasd
    >>asdasdasd
    >>xzczxc
    >>qwewer
    >>werwer|\003'
    >>
    >>ps:there must be \002 at the start and \003 at the end.
    >>thanks.
    >>
    >>

    >
    >Hi,
    >
    >I don't know what you mean with "escape characters".
    >The dot does not match a newline. You have to use the
    >re.DOTALL option if you want this.
    >
    > HTH,
    > Thomas
    >
    >
    >

    thats exactly what i want, how can i use DOTALL, by doing re.compile ?
    thanks
     
    Sinan Nalkaya, Sep 16, 2005
    #3
  4. Sinan Nalkaya wrote:

    > thats exactly what i want, how can i use DOTALL, by doing re.compile ?


    there's always the manual:

    http://docs.python.org/lib/node114.html

    compile(pattern[, flags])

    Compile a regular expression pattern into a regular expression object,
    which can be used for matching using its match() and search() methods,
    described below.

    The expression's behaviour can be modified by specifying a flags value.

    /.../

    S
    DOTALL

    Make the "." special character match any character at all, including a
    newline; without this flag, "." will match anything except a newline.

    /.../

    </F>
     
    Fredrik Lundh, Sep 16, 2005
    #4
    1. Advertisements

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. Jeff S
    Replies:
    12
    Views:
    14,191
    Jeff S
    Nov 10, 2003
  2. George Durzi

    RegisterStartupScript / Escape Character

    George Durzi, Jul 2, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    777
    George Durzi
    Jul 2, 2004
  3. =?Utf-8?B?Q29vbEtpd2lCbG9rZQ==?=

    URL Escape Character Problem (Bug in ASP.NET??)

    =?Utf-8?B?Q29vbEtpd2lCbG9rZQ==?=, Mar 8, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    4,907
    Joerg Jooss
    Mar 10, 2005
  4. \Rob\
    Replies:
    8
    Views:
    898
    Daniel Kirsch
    Feb 24, 2006
  5. Eddy C
    Replies:
    4
    Views:
    1,205
    David N. Welton
    Oct 9, 2005
  6. slomo
    Replies:
    5
    Views:
    2,133
    Duncan Booth
    Dec 2, 2007
  7. Bilal

    Escape Character & and #

    Bilal, Jun 25, 2004, in forum: Javascript
    Replies:
    2
    Views:
    323
    Michael Austin
    Jun 25, 2004
  8. nvangogh
    Replies:
    10
    Views:
    526
    Randy Westlund
    Mar 13, 2014
Loading...