diff --git a/re-pcre/re.py b/re-pcre/re.py index c4e4d43c..d9eaea3d 100644 --- a/re-pcre/re.py +++ b/re-pcre/re.py @@ -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): diff --git a/re-pcre/test_re.py b/re-pcre/test_re.py index 1dc18a5b..9b2a941b 100644 --- a/re-pcre/test_re.py +++ b/re-pcre/test_re.py @@ -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 ']