Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > re and escape character

Reply
Thread Tools

re and escape character

 
 
Sinan Nalkaya
Guest
Posts: n/a
 
      09-15-2005
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.
 
Reply With Quote
 
 
 
 
Thomas Guettler
Guest
Posts: n/a
 
      09-15-2005
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: http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
 
Sinan Nalkaya
Guest
Posts: n/a
 
      09-16-2005
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
 
Reply With Quote
 
Fredrik Lundh
Guest
Posts: n/a
 
      09-16-2005
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>



 
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
How to read strings cantaining escape character from a file and useit as escape sequences? slomo Python 5 12-02-2007 11:39 AM
Re: html special character and escape characters knowledgepays@hotmail.com ASP .Net 0 01-27-2005 02:08 AM
RegisterStartupScript / Escape Character George Durzi ASP .Net 0 07-02-2004 07:08 PM
Escape Character & and # Bilal Javascript 2 06-25-2004 02:08 PM
Problem With String Containing JavaScript Escape Character Jeff S ASP .Net 12 11-10-2003 07:19 PM



Advertisments