python文本导出_python3如何用re导出文本数据?

在小学做题的时候,如果题目中有相同的数值,我们还可以通过人工比对查找出来。不过现在要用电脑处理的数据很多,我们需要借助某种工具,来帮我们筛选出重复的数据或是文件名。那么学了python的我们有没有什么解决办法呢?今天小编就教大家用re导出文本数据,具体举例如下:

文本内容如下,就是一个编译后的map,我想提取里面的symbol信息,地址,以及在哪些模块里面使用了

当下面有多行时,也就是在多个.o文件中使用时,怎么提取出每一个.o

表达式是:_([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:

当需要匹配多个“ ******.o”时如何匹配

问题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']

测试: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']

看完后小伙伴们会发现,我们想要的.o的结果已经出来啦,说明re.findall针对此类问题的解决有效果哦~更多Python学习推荐:JQ教程网Python大全。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值