2025-09-10:仓库迁移

This commit is contained in:
2025-09-10 16:12:45 +08:00
parent e0e49b0ac9
commit 3130e336a1
146 changed files with 4066 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
import re
if __name__ == '__main__':
# 正常情况下,我们会想用.来匹配所有字符串,但这个东西不能匹配换行符
text1 = '/*This is a comment*/'
text2 = '''/*This is a
multiline comment */'''
comment = re.compile(r'/\*(.*?)\*/')
print(comment.findall(text1))
print(comment.findall(text2))
# 你会发现欸我靠咋匹配不到了,那是因为由于没办法识别\n,第二行被抛弃了
# 想要识别出\n,需要使用(?:.|\n)指定一个非捕获组,意思是在识别到/n的时候只做匹配但不触发捕获退出
comment_pro = re.compile(r'\*((?:.|\n)*?)\*/')
print(comment_pro.findall(text2))
# 对于这种简单的情况可以在compile函数中加入一个参数re.DOTALL来让.匹配包括\n在内的所有字符串
# PS复杂情况请另请高明
comment_pro_se = re.compile(r'\*(.*?)\*/', re.DOTALL)
print(comment_pro_se.findall(text2))