diff --git a/unstructured/cleaners/extract.py b/unstructured/cleaners/extract.py index b576f9ccc6..27c5d96601 100644 --- a/unstructured/cleaners/extract.py +++ b/unstructured/cleaners/extract.py @@ -18,12 +18,16 @@ def _get_indexed_match(text: str, pattern: str, index: int = 0) -> re.Match: raise ValueError(f"The index is {index}. Index must be a non-negative integer.") regex_match = None + i = -1 for i, result in enumerate(re.finditer(pattern, text)): if i == index: regex_match = result if regex_match is None: - raise ValueError(f"Result with index {index} was not found. The largest index was {i}.") + message = f"Result with index {index} was not found." + if i >= 0: + message += f" The largest index was {i}." + raise ValueError(message) return regex_match