group 0 in the re module

Y

Yingjie Lan

Hi,

According to the doc, group(0) is the entire match.

But if you do this:'\x00 to 757-234'

where I expected
'757234 to 757-234'

Then I found that in python re '\0' is considered an octal number.
So, is there anyway to refer to the entire match by an escaped
notation?

Thanks,

Yingjie
 
J

J. Gerlach

Am 08.12.2010 03:23, schrieb Yingjie Lan:
Hi,

According to the doc, group(0) is the entire match.


But if you do this:
'\x00 to 757-234'

where I expected
'757234 to 757-234'

Then I found that in python re '\0' is considered an octal number.
So, is there anyway to refer to the entire match by an escaped
notation?

Thanks,

Yingjie
the documentation of the re module says:
\g<number> uses the corresponding group number; \g<2> is
therefore equivalent to \2, but isn’t ambiguous in a replacement such
as \g<2>0. \20 would be interpreted as a reference to group 20, not a
reference to group 2 followed by the literal character '0'. The
backreference \g<0> substitutes in the entire substring matched by
the RE.

... so you're looking for r"\g<0> to \1-\2"
 

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
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top