Scrapegraph-ai/scrapegraphai/utils/cleanup_code.py
2024-09-28 09:02:20 +02:00

12 lines
253 B
Python

"""
This utility function extracts the code from a given string.
"""
import re
def extract_code(code: str) -> str:
pattern = r'```(?:python)?\n(.*?)```'
match = re.search(pattern, code, re.DOTALL)
return match.group(1) if match else code