Spaces:
Sleeping
Sleeping
File size: 774 Bytes
11ae35a c0ed2cf 11ae35a 87abec5 c0ed2cf ca4eb6d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
from traceback import format_exc
from regex import search
from Powers import LOGGER
async def regex_searcher(regex_string: str, string: str) -> str:
"""Search for Regex in string."""
try:
re_search = search(regex_string, string, timeout=6)
except TimeoutError:
return False
except Exception:
LOGGER.error(format_exc())
return False
return re_search
async def infinite_loop_check(regex_string: str) -> bool:
"""Clear Regex in string."""
loop_matches = (
r"\((.{1,}[\+\*]){1,}\)[\+\*]."
r"[\(\[].{1,}\{\d(,)?\}[\)\]]\{\d(,)?\}"
r"\(.{1,}\)\{.{1,}(,)?\}\(.*\)(\+|\* |\{.*\})"
)
for match in loop_matches:
match_1 = search(match, regex_string)
return bool(match_1)
|