I don't understand why the two REs produce a different result. I read
the RE guide but still I can't seem to figure it out. t
'echo user=name password=pass path="/ret files"\r\n' re.findall(r'(?<=\s)[^=]+=((?:".*")|(?:\S*))(?=\s)', t)
['name', 'pass', '"/ret files"'] re.findall(r'(?<=\s)[^=]+=((".*")|(\S*))(?=\s)', t)
[('name', '', 'name'), ('pass', '', 'pass'), ('"/ret files"', '"/ret
files"', '')]
Also, does '|' char (meaning or) produces a pair for each section. I
don't understand how it works. Can someone please direct me to a place
which will explain it?
Thanks. 3 1068
Yoav wrote: I don't understand why the two REs produce a different result. I read the RE guide but still I can't seem to figure it out.
>>> t 'echo user=name password=pass path="/ret files"\r\n' >>> re.findall(r'(?<=\s)[^=]+=((?:".*")|(?:\S*))(?=\s)', t) ['name', 'pass', '"/ret files"'] >>> re.findall(r'(?<=\s)[^=]+=((".*")|(\S*))(?=\s)', t) [('name', '', 'name'), ('pass', '', 'pass'), ('"/ret files"', '"/ret files"', '')]
Hi Yoav.
You can see at "sre" documentation (use that instead of the docs for "re")
that using "?:" you're asking for a non-groupping version of the
parenthesis match. When you use parenthesis, the matched expression is
saved for using later. Using "?:" you prevent that. This is what causes
the difference for you.
Also, does '|' char (meaning or) produces a pair for each section. I don't understand how it works. Can someone please direct me to a place which will explain it?
I didn't get your second question. When you use "|" the first match is
used. It is a short-circuited version of "or". I mean, it tries the first
regexp, if it matches, the second expression is ignored. The same is true
for "and", except that the comparisons end on the first false result.
Be seeing you,
--
Jorge Godoy <go***@ieee.org>
Thanks, it seems like the first answer covers the second as well.
Thank you.
Jorge Godoy wrote: Yoav wrote:
I don't understand why the two REs produce a different result. I read the RE guide but still I can't seem to figure it out.
>>> t 'echo user=name password=pass path="/ret files"\r\n' >>> re.findall(r'(?<=\s)[^=]+=((?:".*")|(?:\S*))(?=\s)', t) ['name', 'pass', '"/ret files"'] >>> re.findall(r'(?<=\s)[^=]+=((".*")|(\S*))(?=\s)', t) [('name', '', 'name'), ('pass', '', 'pass'), ('"/ret files"', '"/ret files"', '')]
Hi Yoav.
You can see at "sre" documentation (use that instead of the docs for "re") that using "?:" you're asking for a non-groupping version of the parenthesis match. When you use parenthesis, the matched expression is saved for using later. Using "?:" you prevent that. This is what causes the difference for you.
Also, does '|' char (meaning or) produces a pair for each section. I don't understand how it works. Can someone please direct me to a place which will explain it?
I didn't get your second question. When you use "|" the first match is used. It is a short-circuited version of "or". I mean, it tries the first regexp, if it matches, the second expression is ignored. The same is true for "and", except that the comparisons end on the first false result.
Be seeing you,
What is the difference between the RE module and the SRE one?
-------- Original Message --------
From: Jorge Godoy <go***@ieee.org>
To:
Subject: Re:RE Question
Date: 18/8/2005 17:44 Yoav wrote:
I don't understand why the two REs produce a different result. I read the RE guide but still I can't seem to figure it out.
>>> t 'echo user=name password=pass path="/ret files"\r\n' >>> re.findall(r'(?<=\s)[^=]+=((?:".*")|(?:\S*))(?=\s)', t) ['name', 'pass', '"/ret files"'] >>> re.findall(r'(?<=\s)[^=]+=((".*")|(\S*))(?=\s)', t) [('name', '', 'name'), ('pass', '', 'pass'), ('"/ret files"', '"/ret files"', '')]
Hi Yoav.
You can see at "sre" documentation (use that instead of the docs for "re") that using "?:" you're asking for a non-groupping version of the parenthesis match. When you use parenthesis, the matched expression is saved for using later. Using "?:" you prevent that. This is what causes the difference for you.
Also, does '|' char (meaning or) produces a pair for each section. I don't understand how it works. Can someone please direct me to a place which will explain it?
I didn't get your second question. When you use "|" the first match is used. It is a short-circuited version of "or". I mean, it tries the first regexp, if it matches, the second expression is ignored. The same is true for "and", except that the comparisons end on the first false result.
Be seeing you, This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mohammed Mazid |
last post by:
Can anyone please help me on how to move to the next and previous
question?
Here is a snippet of my code:
Private Sub cmdNext_Click()
End Sub...
|
by: Stevey |
last post by:
I have the following XML file...
<?xml version="1.0"?>
<animals>
<animal>
<name>Tiger</name>
<questions>
<question index="0">true</question>...
|
by: nospam |
last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types,
so, since it seems to me that Partial Types is still in the design or...
|
by: Ekqvist Marko |
last post by:
Hi,
I have one Access database table including questions and answers. Now
I need to give answer id automatically to questionID column. But I
don't...
|
by: glenn |
last post by:
I am use to programming in php and the way session and post vars are past
from fields on one page through to the post page automatically where I can...
|
by: Rider |
last post by:
Hi, simple(?) question about asp.net configuration..
I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm
first start...
|
by: Jeff |
last post by:
In the function below, can size ever be 0 (zero)?
char *clc_strdup(const char * CLC_RESTRICT s)
{
size_t size;
char *p;
...
|
by: spibou |
last post by:
In the statement "a *= expression" is expression assumed to be
parenthesized ? For example if I write "a *= b+c" is this the same
as "a = a *...
|
by: Allan Ebdrup |
last post by:
Hi,
I'm trying to render a Matrix question in my ASP.Net 2.0 page, A matrix
question is a question where you have several options that can all be...
|
by: Zhang Weiwu |
last post by:
Hello!
I wrote this:
..required-question p:after {
content: "*";
}
Corresponding HTML:
<div class="required-question"><p>Question...
|
by: better678 |
last post by:
Question:
Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct?
Answer:
Java is an object-oriented...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
| |