import re
regex = re.compile(r"(^([#]+|[*-+]\.|[0-9]+\.|[ ]{3,}|[> ]+)\s([^\n]+)$|([*_~\-]+)([^\4]+?)\4|(`+)([^\n]+)?\n([^\6]+?)\6)", flags=re.MULTILINE)
test_str = ("# 标题\n\n"
" 引用\n\n"
"> 缩进\n"
">> 多级缩进\n"
"> > 呵呵\n\n"
"普通文本 *加粗文本* ***特别粗的文本*** ~删除~ _斜体_\n\n"
"```JavaScript\n"
"Code\n"
"```\n\n"
"另一个代码段\n"
"```\n"
"Code\n"
"```\n\n\n"
"## 二级标题\n\n"
"1. 有序 列表一\n"
"2. 有序列表二\n"
"3. 有序列表三\n\n"
"*. 无序列表一\n"
"*. 无序列表二")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html