in curator/indexlist.py [0:0]
def filter_by_regex(self, kind=None, value=None, exclude=False):
"""
Match indices by regular expression (pattern).
:param kind: Can be one of: ``suffix``, ``prefix``, ``regex``, or
``timestring``. This option defines what ``kind`` of filter you will
be building.
:param value: Depends on ``kind``. It is the :py:func:`time.strftime` string if
``kind`` is ``timestring``. It's used to build the regular expression
for other kinds.
:param exclude: If ``exclude=True``, this filter will remove matching
indices from ``indices``. If ``exclude=False``, then only matching
indices will be kept in ``indices``. Default is ``False``
"""
self.loggit.debug('Filtering indices by regex')
if kind not in ['regex', 'prefix', 'suffix', 'timestring']:
raise ValueError(f'{kind}: Invalid value for kind')
# Stop here if None or empty value, but zero is okay
if value == 0:
pass
elif not value:
raise ValueError(
'Invalid None value for "value". Cannot be "None" type, empty, or False'
)
if kind == 'timestring':
regex = settings.regex_map()[kind].format(get_date_regex(value))
else:
regex = settings.regex_map()[kind].format(value)
self.empty_list_check()
pattern = re.compile(regex)
for index in self.working_list():
self.loggit.debug('Filter by regex: Index: %s', index)
match = pattern.search(index)
if match:
self.__excludify(True, exclude, index)
else:
self.__excludify(False, exclude, index)