mirror of
https://github.com/VinciGit00/Scrapegraph-ai.git
synced 2026-06-04 21:01:04 +08:00
17 lines
302 B
Python
17 lines
302 B
Python
"""
|
|
This utility function extracts the code from a given string.
|
|
"""
|
|
|
|
import re
|
|
|
|
|
|
def extract_code(code: str) -> str:
|
|
"""
|
|
Module for extracting code
|
|
"""
|
|
pattern = r"```(?:python)?\n(.*?)```"
|
|
|
|
match = re.search(pattern, code, re.DOTALL)
|
|
|
|
return match.group(1) if match else code
|