import re def extract_value(patterns, primary_source, secondary_source, default='Not Defined'): """Extracts the first match for a list of patterns from the primary source. Falls back to the secondary source if no match is found. """ for source in (primary_source, secondary_source): for pattern in patterns: matches = re.findall(pattern, source, re.IGNORECASE) if matches: return matches[0] # Return the first match immediately return default # Return default if no matches are found