re and escape character

S

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

Thomas Guettler

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
 
S

Sinan Nalkaya

Thomas said:
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
 
F

Fredrik Lundh

Sinan said:
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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top