472,345 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Bug in re module?

Ant
Look at the following minimal example:
>>import re
p = re.compile(r"(:?Test) (String)")
m = p.search("This is a Test String OK?")
m.groups()
('Test', 'String')

I would have expected this to produce:

('String')

since (:?...) should be a non-capturing group. From the module
reference:

(?:...)
A non-grouping version of regular parentheses. Matches whatever
regular expression is inside the parentheses, but the substring matched
by the group cannot be retrieved after performing a match or referenced
later in the pattern.

Oct 6 '06 #1
8 953
Ant

Ant wrote:
Look at the following minimal example:
.... (snip example that shows non-capturing group capturing)

Note I get the same results from python versions 2.4 and 2.5.

Oct 6 '06 #2
In article <11**********************@k70g2000cwa.googlegroups .com>,
"Ant" <an****@gmail.comwrote:
Ant wrote:
Look at the following minimal example:
... (snip example that shows non-capturing group capturing)

Note I get the same results from python versions 2.4 and 2.5.
Try ?: instead of :?

Just
Oct 6 '06 #3

Ant wrote:
Look at the following minimal example:
>import re
p = re.compile(r"(:?Test) (String)")
Bzzzzzt! Sorry, PBKAC.

The correct syntax is (?:foo)
You have (:?foo)
which matches an optional colon followed by foo.

Now quick kill your post before the effbot spots it :-)

>m = p.search("This is a Test String OK?")
m.groups()
('Test', 'String')

I would have expected this to produce:

('String')

since (:?...) should be a non-capturing group. From the module
reference:

(?:...)
A non-grouping version of regular parentheses. Matches whatever
regular expression is inside the parentheses, but the substring matched
by the group cannot be retrieved after performing a match or referenced
later in the pattern.
Oct 6 '06 #4
Ant wrote:
>
I would have expected this to produce:

('String')

since (:?...) should be a non-capturing group. From the module
reference:

(?:...)
(?:...) isn't the same thing as (:?...), though.

</F>

Oct 6 '06 #5
Ant

Just wrote:
Try ?: instead of :?
Duh. Put it down to Friday afternoon!

:-\

Don't know what I was thinking that something as high profile as that
could slip through the net!!

Oct 6 '06 #6
Ant

John Machin wrote:
Now quick kill your post before the effbot spots it :-)
Too late - the post was 3 minutes ago you know ;-)

Oct 6 '06 #7
Ant wrote:
John Machin wrote:
>Now quick kill your post before the effbot spots it :-)

Too late - the post was 3 minutes ago you know ;-)
Must be your lucky day - he did spot it, and you're still alive !-)
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Oct 6 '06 #8
Ant wrote:
John Machin wrote:
>Now quick kill your post before the effbot spots it :-)

Too late - the post was 3 minutes ago you know ;-)
+1 QOTW, BTW

--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Oct 6 '06 #9

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

Similar topics

8
by: Bo Peng | last post by:
Dear list, I am writing a Python extension module that needs a way to expose pieces of a big C array to python. Currently, I am using NumPy like...
8
by: Irmen de Jong | last post by:
What would be the best way, if any, to obtain the bytecode for a given loaded module? I can get the source: import inspect import os src =...
5
by: dody suria wijaya | last post by:
I found this problem when trying to split a module into two. Here's an example: ============== #Module a (a.py): from b import * class Main:...
3
by: David T. Ashley | last post by:
Hi, Red Hat Enterprise Linux 4.X. I'm writing command-line PHP scripts for the first time. I get the messages below. What do they mean? ...
10
by: Bonzol | last post by:
vb.net Hey there, could someone just tell me what the differnce is between classes and modules and when each one would be used compared to the...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote...
40
by: rjcarr | last post by:
Sorry if this is a completely newbie question ... I was trying to get information about the logging.handlers module, so I imported logging, and...
4
by: rkmr.em | last post by:
Hi I have a function data, that I need to import from a file data, in the directory data If I do this from python interactive shell (linux...
0
by: Fredrik Lundh | last post by:
Jeff Dyke wrote: so how did that processing use the "mymodulename" name? the calling method has nothing to do with what's considered to be...
6
by: dudeja.rajat | last post by:
Hi, I found on the net that there is something called module initialization. Unfortunately, there is not much information for this. However,...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
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...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
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...
2
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...
0
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...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
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 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.