Spaces:
Paused
Paused
Download Powers/utils/regex_utils.py from Dragdev/telegrambot: direct link, hf CLI and curl.
- Browser
- Download file 774 Bytes
-
https://huggingface.co/spaces/Dragdev/telegrambot/resolve/85411fa86fdabf8aec00aa307cd5a0adb2b45acf/Powers/utils/regex_utils.py
- Command line
-
hf download hf://spaces/Dragdev/telegrambot@85411fa86fdabf8aec00aa307cd5a0adb2b45acf/Powers/utils/regex_utils.py
-
curl -L -o regex_utils.py https://huggingface.co/spaces/Dragdev/telegrambot/resolve/85411fa86fdabf8aec00aa307cd5a0adb2b45acf/Powers/utils/regex_utils.py
774 Bytes
| 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) | |