Spaces:
Sleeping
Sleeping
File size: 548 Bytes
5fc6c27 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import re
from typing import Any, Dict, List, Literal, Optional, Union, Tuple
import logging as logger
def extract_pattern(content: str, pattern: str) -> Optional[str]:
try:
_pattern = fr"<{pattern}>(.*?)</{pattern}>"
match = re.search(_pattern, content, re.DOTALL)
if match:
text = match.group(1)
return text.strip()
else:
return None
except Exception as e:
logger.warning(f"Error extracting answer: {e}, current content: {content}")
return None
|