Skip to content

Commit 3ec8299

Browse files
committed
re-pcre: findall(): Rework for compliant implementation.
1 parent b3cfd73 commit 3ec8299

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

re-pcre/re.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ def split(self, s, maxsplit=0):
124124

125125
def findall(self, s):
126126
res = []
127+
start = 0
127128
while True:
128-
m = self.search(s)
129+
m = self.search(s, start)
129130
if not m:
130131
return res
131132
if m.num == 1:
@@ -135,7 +136,7 @@ def findall(self, s):
135136
else:
136137
res.append(m.groups())
137138
beg, end = m.span(0)
138-
s = s[end:]
139+
start = end
139140

140141

141142
def compile(pattern, flags=0):

re-pcre/test_re.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,12 @@
4242

4343
text = "He was carefully disguised but captured quickly by police."
4444
assert re.findall(r"(\w+)ly", text) == ['careful', 'quick']
45+
46+
_leading_whitespace_re = re.compile('(^[ \t]*)(?:[^ \t\n])', re.MULTILINE)
47+
text = "\tfoo\n\tbar"
48+
indents = _leading_whitespace_re.findall(text)
49+
assert indents == ['\t', '\t']
50+
51+
text = " \thello there\n \t how are you?"
52+
indents = _leading_whitespace_re.findall(text)
53+
assert indents == [' \t', ' \t ']

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy