This commit is contained in:
marco
2020-06-15 15:30:16 +02:00
parent fe92d9d581
commit 42b81cfbbc
+10 -1
View File
@@ -41,7 +41,16 @@ def printMatches(matches):
def find_single_match(data, patron, index=0): def find_single_match(data, patron, index=0):
try: try:
if index == 0: if index == 0:
matches = re.search(patron, data, flags=re.DOTALL).groups() matches = re.search(patron, data, flags=re.DOTALL)
if matches:
if len(matches.groups()) == 1:
return matches.group(1)
elif len(matches.groups()) > 1:
return matches.groups()
else:
return matches.group()
else:
return []
else: else:
matches = re.findall(patron, data, flags=re.DOTALL) matches = re.findall(patron, data, flags=re.DOTALL)
return matches[index] return matches[index]