find_matched_str

pyhelpers.text.find_matched_str(x, lookup_list)[source]

Find all that are matched with a string from among a sequence of strings.

Parameters:
  • x (str) – a string-type variable

  • lookup_list (Iterable) – a sequence of strings for lookup

Returns:

a generator containing all that are matched with x

Return type:

Generator | None

Examples:

>>> from pyhelpers.text import find_matched_str

>>> lookup_lst = ['abc', 'aapl', 'app', 'ap', 'ape', 'apex', 'apel']
>>> res = find_matched_str('apple', lookup_lst)
>>> list(res)
[]

>>> lookup_lst += ['apple']
>>> lookup_lst
['abc', 'aapl', 'app', 'ap', 'ape', 'apex', 'apel', 'apple']

>>> res = find_matched_str('apple', lookup_lst)
>>> list(res)
['apple']

>>> res = find_matched_str(r'app(le)?', lookup_lst)
>>> list(res)
['app', 'apple']