20 lines
585 B
Python
20 lines
585 B
Python
def extract_geogebra_code(file_path):
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
import re
|
|
# 匹配代码块内容(不含标记)
|
|
pattern = r'```geogebra\n(.*?)\n```'
|
|
match = re.search(pattern, content, re.DOTALL)
|
|
|
|
if match:
|
|
# 移除首尾空白行并返回纯代码内容
|
|
code_content = match.group(1).strip()
|
|
return code_content
|
|
return ''
|
|
|
|
|
|
# 使用示例
|
|
file_path = r'd:\dsWork\dsProject\dsLightRag\GeoGeBra\GGB.txt'
|
|
result = extract_geogebra_code(file_path)
|
|
print(result) |