1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python程序中想使用正则表达式_如何在python中使用正则表达式提取每行中需要的信息...

python程序中想使用正则表达式_如何在python中使用正则表达式提取每行中需要的信息...

时间:2021-04-19 11:21:41

相关推荐

python程序中想使用正则表达式_如何在python中使用正则表达式提取每行中需要的信息...

展开全部

>>>s='''218996%S15173928K38024Kfgapp_108com.tencent.qq

2189934%S14191436K50888Kfgapp_108com.tencent.qq

2189949%S14183928K41584Kfgapp_108com.tencent.qq

2189928%S15176984K40240Kfgapp_108com.tencent.qq

218996%S15177004K40448Kfgapp_108com.tencent.qq

218996%S14176048K40564Kfgapp_108com.tencent.qq

2189910%S14176196K40472Kfgapp_108com.tencent.qq

218999%S14176232K40712Kfgapp_108com.tencent.qq

2189912%S14176288K40820Kfgapp_108com.tencent.qq

2189910%S14176288K40820Kfgapp_108com.tencent.qq

2189912%S16179376K40904Kfgapp_108com.tencent.qq'''

>>>open('a.txt','w').write(s)

>>>f=open('a.txt')

>>>f.read()

'218996%S15173928K38024Kfgapp_108com.tencent.qq\n2189934%S14191436K50888Kfgapp_108com.tencent.qq\n2189949%S14183928K41584Kfgapp_108com.tencent.qq\n2189928%S15176984K40240Kfgapp_108com.tencent.qq\n218996%S15177004K40448Kfgapp_108com.tencent.qq\n218996%S14176048K40564Kfgapp_108com.tencent.qq\n2189910%S14176196K40472Kfgapp_108com.tencent.qq\n218999%S14176232K40712Kfgapp_108com.tencent.qq\n2189912%S14176288K40820Kfgapp_108com.tencent.qq\n2189910%S14176288K40820Kfgapp_108com.tencent.qq\n2189912%S16179376K40904Kfgapp_108com.tencent.qq'

>>>pprint.pprint(map(lambdax:re.findall('\d+?+?(\d+%)+?S+?\d+?+?(\d+K)+?(\d+K)',x),s.split('\n')))

[[('6%','173928K','38024K')],

[('34%','191436K','50888K')],

[('49%','183928K','41584K')],

[('28%','176984K','40240K')],

[('6%','177004K','40448K')],

[('6%','176048K','40564K')],

[('10%','176196K','40472K')],

[('9%','176232K','40712K')],

[('12%','176288K','40820K')],

[('10%','176288K','40820K')],

[('12%','179376K','40904K')]]

>>>pprint.pprint(map(lambdax:re.findall('\d+?+?(\d+%)+?S+?\d+?+?(\d+K)+?(\d+K)',x),open('a.txt').read().split('\n')))

[[('6%','173928K','38024K')],

[('34%','191436K','50888K')],

[('49%','183928K','41584K')],

[('28%','176984K','40240K')],

[('6%','177004K','40448K')],

[('6%','176048K','40564K')],

[('10%','176196K','40472K')],

[('9%','176232K','40712K')],

[('12%','176288K','40820K')],

[('10%','176288K','40820K')],

[('12%','179376K','40904K')]]

>>>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。