You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
swarms/swarms/utils/parse_code.py

12 lines
370 B

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