find_matched_str¶
- pyhelpers.text.find_matched_str(x, lookup_list)[source]¶
Find all strings in a sequence that match a given string.
- Parameters:
x (str) – The string to match.
lookup_list (Iterable) – A sequence of strings for lookup.
- Returns:
A generator containing all strings that match
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']