kopia lustrzana https://github.com/micropython/micropython-lib
re-pcre: Implement multiple args to match.group().
rodzic
a252332423
commit
ef315ca90e
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Ładowanie…
Reference in New Issue