Am 08.12.2010 03:23, schrieb Yingjie Lan:
> Hi,
>
> According to the doc, group(0) is the entire match.
>
m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
m.group(0) # The entire match 'Isaac Newton'
>
> But if you do this:
import re
re.sub(r'(\d{3})(\d{3})', r'\0 t
: Use \g<0>.
Thanks!
Though I wish all \1, \2, ..., should also be forbidden.
Such a mixture of things looks like a patch work.
No offense meant.
Yingjie
--
http://mail.python.org/mailman/listinfo/python-list
On 08/12/2010 02:23, Yingjie Lan wrote:
Hi,
According to the doc, group(0) is the entire match.
m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
m.group(0) # The entire match 'Isaac Newton'
But if you do this:
import re
re.sub(r'(\d{3})(\d{3})', r'\0 to \1-\2', '757234')
'\x00 to 75
Hi,
According to the doc, group(0) is the entire match.
>>> m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
>>> m.group(0) # The entire match 'Isaac Newton'
But if you do this:
>>> import re
>>> re.sub(r'(\d{3})(\d{3})', r'\0 to \1-\2', '757234')
'\x00 to 757-234'
where I expected
'7