parse code function in utils

pull/69/head
Kye 1 year ago
parent 6c325a745e
commit e4c2de3c54

@ -1,3 +1,4 @@
from swarms.utils.display_markdown import display_markdown_message
from swarms.utils.futures import execute_futures_dict
from swarms.utils.code_interpreter import SubprocessCodeInterpreter
from swarms.utils.parse_code import extract_code_in_backticks_in_string

@ -0,0 +1,11 @@
import re
def extract_code_in_backticks_in_string(message: str) -> str:
"""
To extract code from a string in markdown and return a string
"""
pattern = r"`` ``(.*?)`` " # Non-greedy match between six backticks
match = re.search(pattern, message, re.DOTALL) # re.DOTALL to match newline chars
return match.group(1).strip() if match else None
Loading…
Cancel
Save