首页 > 解决方案 > 从字符串中,如何在 rgb 之后的括号之间提取值?

问题描述

这是我上一篇文章的分支Python get info from long complex string

style="fill: rgb(100, 2, 5); fill-opacity: 1; font-family: ProjectStocksFont; font-size: 70px; font-weight: normal; font-style: normal; text-decoration: none;"
print(rgb[0], rgb[1], rgb[2])
# 100 2 5

标签: pythonregex

解决方案


我会将字符串从左括号拼接到右括号,然后使其成为一个列表。就像是:

rgb = style[style.find("(") + 1:style.find(")")].split(", ")

rgb 将是一个列表: ['100' , '2' , '5']


推荐阅读