diff --git a/librefi/utils.py b/librefi/utils.py index 4b2cd6a..dba11f6 100644 --- a/librefi/utils.py +++ b/librefi/utils.py @@ -89,13 +89,25 @@ def get_email_address(): ]) -def regex_search_string(regexes, string, default=None): +def regex_search_string(regexes, string, default=None, multiple=False, whole_match=False): if not isinstance(regexes, list): regexes = [regexes] + results = [] for regex in regexes: - match = re.search(regex, string) - if match: - return match.group(1) + if multiple: + matches = re.finditer(regex, string) + for match in matches: + if not whole_match: + match = match.group(1) + results.append(match) + else: + match = re.search(regex, string) + if match: + if not whole_match: + match = match.group(1) + return match + if multiple: + return results return default diff --git a/tests/regex_utils.py b/tests/regex_utils.py index 0cf632e..c0fdc2e 100644 --- a/tests/regex_utils.py +++ b/tests/regex_utils.py @@ -3,31 +3,34 @@ from librefi.utils import regex_search_string HTML_STRING = """
""" -PATTERN = r'