gpt4 book ai didi

Python:从css文件中提取注释

转载 作者:太空宇宙 更新时间:2023-11-04 04:16:30 25 4
gpt4 key购买 nike

我想提取 CSS 文件的第一个注释 block ,如下所示:

/*
author : name
uri : link
etc
*/

不提取其他评论

/* header */
/* footer */

所以我试了一下:

print re.findall(r'\/\*(.*)\*\/', cssText )

这给了我除我需要的 block 之外的所有其他评论。所以我把它改成了这个,更准确地说:

print re.findall(r'\/\*\n(.*)^\*\/', cssText )

结果什么也没有:

[]

你有什么建议吗?谢谢:-)

最佳答案

如果您只需要第一个评论,您可以只使用第一个结果:

print re.findall(r'\/\*(.*)\*\/', cssText )[0]

您还可以使用 re.search搜索第一个匹配项:

print re.search(r'\/\*(.*)\*\/', cssText )

关于Python:从css文件中提取注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19843801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com