8000 Merge pull request #7 from davidblewett/rure-nonmatching-captures · davidblewett/rure-python@1ddc4d2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ddc4d2

Browse files
authored
Merge pull request #7 from davidblewett/rure-nonmatching-captures
Rure nonmatching captures
2 parents 4c50b75 + 568b62e commit 1ddc4d2

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

rure/lib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ def captures(self, haystack, start=0):
213213
):
214214
return self.capture_cls(*[
215215
RureMatch(match.start, match.end)
216+
if _lib.rure_captures_at(captures, i, match) else None
216217
for i in range(0, _lib.rure_captures_len(captures))
217-
if _lib.rure_captures_at(captures, i, match)
218218
])
219219

220220
@accepts_bytes
@@ -235,8 +235,8 @@ def captures_iter(self, haystack, start=0):
235235
captures):
236236
yield self.capture_cls(*[
237237
RureMatch(match.start, match.end)
238+
if _lib.rure_captures_at(captures, i, match) else None
238239
for i in range(0, _lib.rure_captures_len(captures))
239 FE96 -
if _lib.rure_captures_at(captures, i, match)
240240
])
241241

242242
@accepts_bytes

rure/tests/test_regexobject.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
from __future__ import print_function
4+
import re
5+
import unittest
6+
7+
import rure
8+
9+
10+
class TestRegexObject(unittest.TestCase):
11+
def test_search(self):
12+
ptn = u"(re).*(ger)"
13+
email = u"tony@tiremove_thisger.net"
14+
results = rure.search(ptn, email)
15+
stdlib_results = re.search(ptn, email)
16+
self.assertIsNotNone(results)
17+
self.assertEqual(len(results.groups()),
18+
len(stdlib_results.groups()))
19+
20+
ptn = u"(re)|(ger)"
21+
results = rure.search(ptn, email)
22+
stdlib_results = re.search(ptn, email)
23+
self.assertIsNotNone(results)
24+
self.assertEqual(len(results.groups()),
25+
len(stdlib_results.groups()))
26+
self.assertItemsEqual(results.group(0),
27+
stdlib_results.group(0))

0 commit comments

Comments
 (0)
0