Commit 2b2b3f9b authored by Guido van Rossum's avatar Guido van Rossum

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.
parent 054f8fd1
...@@ -203,6 +203,7 @@ class RegexObject: ...@@ -203,6 +203,7 @@ class RegexObject:
if type(g)==type( "" ): g = [g] if type(g)==type( "" ): g = [g]
results[len(results):] = list(g) results[len(results):] = list(g)
pos = lastmatch = j pos = lastmatch = j
n = n + 1
results.append(source[lastmatch:]) results.append(source[lastmatch:])
return results return results
...@@ -259,11 +260,13 @@ class MatchObject: ...@@ -259,11 +260,13 @@ class MatchObject:
def groups(self): def groups(self):
"Return a tuple containing all subgroups of the match object" "Return a tuple containing all subgroups of the match object"
result = []
# If _num_regs==1, we don't want to call self.group with an for g in range(1, self.re._num_regs):
# empty tuple. if (self.regs[g][0] == -1) or (self.regs[g][1] == -1):
if self.re._num_regs == 1: return () result.append(None)
return apply(self.group, tuple(range(1, self.re._num_regs) ) ) else:
result.append(self.string[self.regs[g][0]:self.regs[g][1]])
return tuple(result)
def group(self, *groups): def group(self, *groups):
"Return one or more groups of the match." "Return one or more groups of the match."
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment