Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

Fix: Correct regex pattern to accurately match code blocks in Markdown

shenchucheng991bfd6f6837
diff --git a/metagpt/utils/common.py b/metagpt/utils/common.py
index b58ac99da..72dc6ab94 100644
--- a/metagpt/utils/common.py
+++ b/metagpt/utils/common.py
@@ -275,7 +275,7 @@ class CodeParser:
def parse_code(cls, text: str, lang: str = "", block: Optional[str] = None) -> str:
if block:
text = cls.parse_block(block, text)
- pattern = rf"```{lang}.*?\s+(.*?)```"
+ pattern = rf"```{lang}.*?\s+(.*?)\n```"
match = re.search(pattern, text, re.DOTALL)
if match:
code = match.group(1)