Re: group 0 in the re module

2010-12-08 Thread J. Gerlach
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

Re: group 0 in the re module

2010-12-07 Thread Yingjie Lan
: 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

Re: group 0 in the re module

2010-12-07 Thread MRAB
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

group 0 in the re module

2010-12-07 Thread 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 to \1-\2', '757234') '\x00 to 757-234' where I expected '7