为什么我的python3.5重新匹配()grep e工作时返回None?

2024-09-30 01:31:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图解析SVG文件的一部分,以获得十六进制填充颜色(比如#ceff80等)

当我使用Bashgrep命令执行此操作时:

grep -o -e "fill:#[a-f, 0-9]*;" Sample.svg

结果如下:

^{pr2}$

但是当我用Python的re模块尝试时,我得到了None

import re
color = re.match(r'fill:#[a-f, 0-9]*;', style)

这是在使用ElementTree遍历XML结构的循环中调用的。style字符串包含如下值:

font-style:normal;font-weight:normal;font-size:40px;line-height:125%;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;display:inline;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;filter:url(#filter5107)

我想提取fill:#xxxxxx;color,然后用[6:-1]范围表达式截断它,以便进一步处理。在

由于某些原因,它总是返回None类型的对象。在

我做错什么了?在


Tags: 文件svgrenonestrokestyle颜色fill

热门问题