MCPcopy Create free account
hub / github.com/davidblewett/rure-python / group

Method group

rure/regex.py:199–228  ·  view source on GitHub ↗
(self, *groups, **kwargs)

Source from the content-addressed store, hash-verified

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)

Callers 6

groupsMethod · 0.95
groupdictMethod · 0.95
test_groupMethod · 0.45
test_group_last_matchMethod · 0.45

Calls 1

getMethod · 0.45

Tested by 4

test_groupMethod · 0.36
test_group_last_matchMethod · 0.36