473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

re and escape character

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.
Sep 15 '05 #1
3 1669
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: ni**************@thomas-guettler.de

Sep 15 '05 #2
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
Sep 16 '05 #3
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>

Sep 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Jon Maz | last post by:
Hi, I have been getting hopelessly confused with escaping escape characters in JScript! All I want to do is write a simple funtion: function DoubleUpBackSlash(inputString) { ??????? }
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
18
by: Steve Litvack | last post by:
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1...
4
by: Guadala Harry | last post by:
I need to place the following into a string... How can I properly escape the % " / < and > characters? <table width="100%" border="0" cellspacing="0" cellpadding="4px" class="hfAll"></Table> ...
7
by: Steve | last post by:
string str ="\"C:\Program Files\Internet Explorer\iexplore.exe\" -nohome" How can I remove charcter to string str = ="C:\Program Files\Internet Explorer\iexplore.exe -nohome"
12
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
15
by: pkaeowic | last post by:
I am having a problem with the "escape" character \e. This code is in my Windows form KeyPress event. The compiler gives me "unrecognized escape sequence" even though this is documented in MSDN....
131
by: Lawrence D'Oliveiro | last post by:
The "escape" function in the "cgi" module escapes characters with special meanings in HTML. The ones that need escaping are '<', '&' and '"'. However, cgi.escape only escapes the quote character if...
3
by: qilin | last post by:
I am trying to save a big text string into MySQL, but I guess i need escape the string firstly, anybody knows any escape function in c for that? or any other suggests ?
5
by: vlsidesign | last post by:
The printf function returns "warning: unknown escape sequence: \040" for a backslash-space combination. If the ascii decimal number for space is 32 and the backslash is 92, why this particular...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.