kopia lustrzana https://github.com/micropython/micropython-lib
re-pcre: findall(): Rework for compliant implementation.
rodzic
b3cfd73659
commit
3ec82997d5
|
@ -124,8 +124,9 @@ class PCREPattern:
|
|||
|
||||
def findall(self, s):
|
||||
res = []
|
||||
start = 0
|
||||
while True:
|
||||
m = self.search(s)
|
||||
m = self.search(s, start)
|
||||
if not m:
|
||||
return res
|
||||
if m.num == 1:
|
||||
|
@ -135,7 +136,7 @@ class PCREPattern:
|
|||
else:
|
||||
res.append(m.groups())
|
||||
beg, end = m.span(0)
|
||||
s = s[end:]
|
||||
start = end
|
||||
|
||||
|
||||
def compile(pattern, flags=0):
|
||||
|
|
|
@ -42,3 +42,12 @@ assert re.findall(r"(\w+)(ly)", text) == [('careful', 'ly'), ('quick', 'ly')]
|
|||
|
||||
text = "He was carefully disguised but captured quickly by police."
|
||||
assert re.findall(r"(\w+)ly", text) == ['careful', 'quick']
|
||||
|
||||
_leading_whitespace_re = re.compile('(^[ \t]*)(?:[^ \t\n])', re.MULTILINE)
|
||||
text = "\tfoo\n\tbar"
|
||||
indents = _leading_whitespace_re.findall(text)
|
||||
assert indents == ['\t', '\t']
|
||||
|
||||
text = " \thello there\n \t how are you?"
|
||||
indents = _leading_whitespace_re.findall(text)
|
||||
assert indents == [' \t', ' \t ']
|
||||
|
|
Ładowanie…
Reference in New Issue