溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

python3怎么用re導(dǎo)出文本數(shù)據(jù)

發(fā)布時(shí)間:2020-11-21 09:20:50 來源:億速云 閱讀:148 作者:小新 欄目:編程語言

小編給大家分享一下python3怎么用re導(dǎo)出文本數(shù)據(jù),相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

文本內(nèi)容如下,就是一個(gè)編譯后的map,我想提取里面的symbol信息,地址,以及在哪些模塊里面使用了

當(dāng)下面有多行時(shí),也就是在多個(gè).o文件中使用時(shí),怎么提取出每一個(gè).o

表達(dá)式是:

_([a-zA-Z0-9_]+)\s+([a-z0-9A-Z]{8})\s+defined\s+in\s+[a-zA-Z0-9_]+.o\s+section\s+.+\n\s+used in\s+([a-zA-Z0-9_]+.o)\s*\n\s*(\w+.o)\n\s*(\w+.o)

問題1:

當(dāng)需要匹配多個(gè)“ ******.o”時(shí)如何匹配

問題2:

如何把所有滿足條件的都匹配出來,

_PfTORQ_r_ThermEffCorrMult 000fe417 defined in torqmall.o section .bss
used in torqmctl.o
torqmrat.o
_PeTORQ_GearState 000fe419 defined in torqmall.o section .bss
used in torq_meth_jac.o
torq_mulf_jac.o
torqmgve.o
torqmgvv.o
etcdmtps.o
_PeTORQ_GearStatePrev 000fe41a defined in torqmall.o section .bss
_PeTORQ_GearStateDsrd 000fe41b defined in torqmall.o section .bss
_VfTORQ_AXIS_RPM_W_11Brk 000fe41c defined in torqmall.o section .bss
used in torqmdes.o
tqdrmall.o

解決方法:

 re.findall(pattern, string, flags=0)

范例:

>>> text = "He was carefully disguised but captured quickly by police."
>>> re.findall(r"\w+ly", text)
['carefully', 'quickly']

測(cè)試:

In [1]: yourstr="""_PfTORQ_r_ThermEffCorrMult 000fe417 defined in torqmall.o section .bss
used in torqmctl.o
torqmrat.o
_PeTORQ_GearState 000fe419 defined in torqmall.o section .bss
used in torq_meth_jac.o
torq_mulf_jac.o
torqmgve.o
torqmgvv.o
etcdmtps.o
_PeTORQ_GearStatePrev 000fe41a defined in torqmall.o section .bss
_PeTORQ_GearStateDsrd 000fe41b defined in torqmall.o section .bss
_VfTORQ_AXIS_RPM_W_11Brk 000fe41c defined in torqmall.o section .bss
used in torqmdes.o
tqdrmall.o"""
 
In [2]: re.findall('\w+\.o',yourstr)
Out[2]:
['torqmall.o',
 'torqmctl.o',
 'torqmrat.o',
 'torqmall.o',
 'torq_meth_jac.o',
 'torq_mulf_jac.o',
 'torqmgve.o',
 'torqmgvv.o',
 'etcdmtps.o',
 'torqmall.o',
 'torqmall.o',
 'torqmall.o',
 'torqmdes.o',
 'tqdrmall.o']

以上是python3怎么用re導(dǎo)出文本數(shù)據(jù)的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI