Returns the capture groups corresponding to the leftmost-first match in text. Capture group 0 always corresponds to the entire match. If no match is found, then None is returned. You should only use captures if you need access to submatches. Otherwise, find is faster
(self, haystack, start=0)
| 174 | |
| 175 | @accepts_bytes |
| 176 | def captures(self, haystack, start=0): |
| 177 | """Returns the capture groups corresponding to the leftmost-first match |
| 178 | in text. Capture group 0 always corresponds to the entire match. |
| 179 | If no match is found, then None is returned. |
| 180 | |
| 181 | You should only use captures if you need access to submatches. |
| 182 | Otherwise, find is faster for discovering the location of the overall |
| 183 | match. |
| 184 | """ |
| 185 | hlen = len(haystack) |
| 186 | captures = _native.ffi.gc(_native.lib.rure_captures_new(self._ptr), |
| 187 | _native.lib.rure_captures_free) |
| 188 | match = _native.ffi.new('rure_match *') |
| 189 | if _native.lib.rure_find_captures( |
| 190 | self._ptr, |
| 191 | haystack, |
| 192 | hlen, |
| 193 | start, |
| 194 | captures |
| 195 | ): |
| 196 | return self.capture_cls(*[ |
| 197 | RureMatch(match.start, match.end) |
| 198 | if _native.lib.rure_captures_at(captures, i, match) else None |
| 199 | for i in range(0, _native.lib.rure_captures_len(captures)) |
| 200 | ]) |
| 201 | |
| 202 | @accepts_bytes |
| 203 | def captures_iter(self, haystack, start=0): |