diff options
author | Guido van Rossum <guido@python.org> | 1998-01-12 18:57:53 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-01-12 18:57:53 (GMT) |
commit | 2b2b3f9bcb7d1cdf97b68f825489b5abfd42cf22 (patch) | |
tree | 241e34e157c18519d2814c0ba592194c9b1b8bce /Lib | |
parent | 054f8fd12cda4e5f3e211ca15347960e8d37fa40 (diff) | |
download | cpython-2b2b3f9bcb7d1cdf97b68f825489b5abfd42cf22.zip cpython-2b2b3f9bcb7d1cdf97b68f825489b5abfd42cf22.tar.gz cpython-2b2b3f9bcb7d1cdf97b68f825489b5abfd42cf22.tar.bz2 |
Fix two bugs:
(1) maxsplit was ignored in split().
(2) groups() would return a string instead of a singleton tuple when
there was only one group.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/re.py | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -203,6 +203,7 @@ class RegexObject: if type(g)==type( "" ): g = [g] results[len(results):] = list(g) pos = lastmatch = j + n = n + 1 results.append(source[lastmatch:]) return results @@ -259,11 +260,13 @@ class MatchObject: def groups(self): "Return a tuple containing all subgroups of the match object" - - # If _num_regs==1, we don't want to call self.group with an - # empty tuple. - if self.re._num_regs == 1: return () - return apply(self.group, tuple(range(1, self.re._num_regs) ) ) + result = [] + for g in range(1, self.re._num_regs): + if (self.regs[g][0] == -1) or (self.regs[g][1] == -1): + result.append(None) + else: + result.append(self.string[self.regs[g][0]:self.regs[g][1]]) + return tuple(result) def group(self, *groups): "Return one or more groups of the match." |