Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74041
| X-Received | by 10.224.41.74 with SMTP id n10mr11523807qae.1.1404671174433; Sun, 06 Jul 2014 11:26:14 -0700 (PDT) |
|---|---|
| X-Received | by 10.140.47.102 with SMTP id l93mr440427qga.5.1404671174398; Sun, 06 Jul 2014 11:26:14 -0700 (PDT) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!i13no6465507qae.1!news-out.google.com!a8ni6411qaq.1!nntp.google.com!i13no6465502qae.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Sun, 6 Jul 2014 11:26:14 -0700 (PDT) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=64.229.140.25; posting-account=SZ_svQkAAACWRFG2bDA-zgq8ILyl4-vo |
| NNTP-Posting-Host | 64.229.140.25 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| 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 |
| Injection-Date | Sun, 06 Jul 2014 18:26:14 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-Received-Bytes | 1932 |
| X-Received-Body-CRC | 238727635 |
| Xref | csiph.com comp.lang.python:74041 |
Show key headers only | 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 | Next — Next in thread | Find similar | Unroll 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