Spaces:
Running
Running
Update utils.py
Browse files
utils.py
CHANGED
@@ -76,7 +76,10 @@ def set_text_bg_color(pattern: str, text: str, color: str = "yellow") -> str:
|
|
76 |
"""
|
77 |
|
78 |
# Find all matches
|
79 |
-
matches = set(re.findall(pattern, text, flags=re.IGNORECASE))
|
|
|
|
|
|
|
80 |
|
81 |
replace_dict = {re.escape(m): f'<span style="background-color:{color}">{m}</span>' for m in matches}
|
82 |
pattern = re.compile("|".join(replace_dict.keys()))
|
|
|
76 |
"""
|
77 |
|
78 |
# Find all matches
|
79 |
+
matches = set(re.findall(re.escape(pattern), text, flags=re.IGNORECASE))
|
80 |
+
if len(matches) == 0:
|
81 |
+
# No matches found
|
82 |
+
return text
|
83 |
|
84 |
replace_dict = {re.escape(m): f'<span style="background-color:{color}">{m}</span>' for m in matches}
|
85 |
pattern = re.compile("|".join(replace_dict.keys()))
|