| 197 | raise NotImplementedError |
| 198 | |
| 199 | def group(self, *groups, **kwargs): |
| 200 | default = kwargs.get('default', None) |
| 201 | decode = kwargs.get('decode', True) |
| 202 | if not groups: |
| 203 | start, end = self.captures[0].start, self.captures[0].end |
| 204 | if decode: |
| 205 | return self.string[start:end].decode('utf8') |
| 206 | else: |
| 207 | return self.string[start:end] |
| 208 | |
| 209 | capture_data = [] |
| 210 | for i in groups: |
| 211 | if isinstance(i, string_types): |
| 212 | match = getattr(self.captures, i) |
| 213 | else: |
| 214 | if i < 0: |
| 215 | raise IndexError(i) |
| 216 | match = self.captures[i] |
| 217 | if match is None: |
| 218 | capture_data.append(default) |
| 219 | else: |
| 220 | data = self.string[match.start:match.end] |
| 221 | if decode: |
| 222 | capture_data.append(data.decode('utf8')) |
| 223 | else: |
| 224 | capture_data.append(data) |
| 225 | if len(groups) == 1: |
| 226 | return capture_data[0] |
| 227 | else: |
| 228 | return tuple(capture_data) |
| 229 | |
| 230 | def groups(self, default=None): |
| 231 | # Exclude the entire match (index 0) |