re-pcre: Implement multiple args to match.group().

pull/118/head
Paul Sokolovsky 2014-05-10 19:09:03 +03:00
rodzic a252332423
commit ef315ca90e
2 zmienionych plików z 5 dodań i 2 usunięć

Wyświetl plik

@ -39,8 +39,10 @@ class PCREMatch:
self.num = num_matches
self.offsets = offsets
def group(self, n):
return self.s[self.offsets[n*2]:self.offsets[n*2+1]]
def group(self, *n):
if len(n) == 1:
return self.s[self.offsets[n[0]*2]:self.offsets[n[0]*2+1]]
return tuple(self.s[self.offsets[i*2]:self.offsets[i*2+1]] for i in n)
def groups(self, default=None):
assert default is None

Wyświetl plik

@ -17,5 +17,6 @@ assert re.sub("a", lambda m: m.group(0) * 2, "caaab") == "caaaaaab"
m = re.match(r"(\d+)\.(\d+)", "24.1632")
assert m.groups() == ('24', '1632')
assert m.group(2, 1) == ('1632', '24')
assert re.escape(r"1243*&[]_dsfAd") == r"1243\*\&\[\]_dsfAd"