def when(self, matches, context): expected_rebulk = Rebulk().defaults(name='release_group') for expected_group in context.get('expected_group'): if expected_group.startswith('re:'): expected_group = expected_group[3:] expected_group = expected_group.replace(' ', '-') expected_rebulk.regex(expected_group, abbreviations=[dash], flags=re.IGNORECASE) else: expected_rebulk.string(expected_group, ignore_case=True) matches = expected_rebulk.matches(matches.input_string, context) return matches