Python从复杂的长字符串中获取信息 [英] Python get info from long complicated string
本文介绍了Python从复杂的长字符串中获取信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从我解析的字符串中获取信息.我正在尝试获取字体大小.这是我返回的字符串
Im trying to get info from strings that I have parsed. Im trying to get the font size. This is the string Im returning
style="fill: rgb(0, 0, 0); fill-opacity: 1; font-family: ProjectStocksFont; font-size: 70px; font-weight: normal; font-style: normal; text-decoration: none;"
我正在尝试从 font-size
获取 70
什么是最好的方法?
Im trying to get 70
from font-size
what would the best way to do that be?
推荐答案
您可以使用 re
模块完成任务:
You can use re
module for the task:
style="fill: rgb(0, 0, 0); fill-opacity: 1; font-family: ProjectStocksFont; font-size: 70px; font-weight: normal; font-style: normal; text-decoration: none;"
import re
print( re.search(r'font-size:\s*(\d+)', style)[1] )
打印:
70
这篇关于Python从复杂的长字符串中获取信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文