Bug in re module?

A

Ant

Look at the following minimal example:
('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.
 
A

Ant

Ant said:
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.
 
J

Just

"Ant said:
... (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
 
F

Fredrik Lundh

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>
 
J

John Machin

Ant said:
Look at the following minimal example:

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 :)
 
A

Ant

Just said:
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!!
 

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,013
Latest member
KatriceSwa

Latest Threads

Top