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

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

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

    RegisterStartupScript / Escape Character

    George Durzi, Jul 2, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    652
    George Durzi
    Jul 2, 2004
  3. slomo
    Replies:
    5
    Views:
    1,625
    Duncan Booth
    Dec 2, 2007
  4. Bilal

    Escape Character & and #

    Bilal, Jun 25, 2004, in forum: Javascript
    Replies:
    2
    Views:
    235
    Michael Austin
    Jun 25, 2004
  5. nvangogh
    Replies:
    10
    Views:
    203
    Randy Westlund
    Mar 13, 2014
Loading...

Share This Page