Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74041

What is the difference between matchObj.group() and matchObj.group(0)

Newsgroups comp.lang.python
Date 2014-07-06 11:26 -0700
Message-ID <809dbbdf-b452-4f25-a1ff-f00a2202939d@googlegroups.com> (permalink)
Subject What is the difference between matchObj.group() and matchObj.group(0)
From rxjwg98@gmail.com

Show all headers | View raw


Hi,

I cannot get the difference between matchObj.group() and matchObj.group(0),
Although there definitions are obvious different. And group() mentions 'tuple'.
tuple means all the elements in line object?



Match Object Methods

Description

group(num=0) This method returns entire match (or specific subgroup num) 
groups()     This method returns all matching subgroups in a tuple 
             (empty if there weren't any) 



I run the following code. Even I add more words to line object, Both have the
same output.

Could you clarify this question?


Thanks again.





#!/usr/bin/python
import re

line = "Cats are smarter than dogs"

matchObj = re.match( r'(.*) are (.*?) .*', line, re.M|re.I)

if matchObj:
   print "matchObj.group() : ", matchObj.group()
   print "matchObj.group(1) : ", matchObj.group(1)
   print "matchObj.group(2) : ", matchObj.group(2)
else:
   print "No match!!"

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

What is the difference between matchObj.group() and matchObj.group(0) rxjwg98@gmail.com - 2014-07-06 11:26 -0700
  Re: What is the difference between matchObj.group() and matchObj.group(0) MRAB <python@mrabarnett.plus.com> - 2014-07-06 20:13 +0100

csiph-web