@master = Array.new(4) { Array.new(2) { Array.new() } }
我想只打印RequestId=159dd0dc-3ac2-11e7-9f57-b7548c7a91e2
global-action-trace=15a01af3-3ac2-11e7-babe-0a5b00b90000
EOE
RequestId=12780045-3ac2-11e7-8dc6-f7c2b766d8e7
global-action-trace=1278c342-3ac2-11e7-babe-0a5b00b90000
EOE
并重视Python中的可能性
答案 0 :(得分:0)
只需使用regex
即可。括号()
内的表达式是您要提取的内容。
print re.findall('RequestId=([A-Za-z0-9 -=]+)', s)
#Output:
#['159dd0dc-3ac2-11e7-9f57-b7548c7a91e2 global-action-trace=15a01af3-3ac2-11e7-babe-0a5b00b90000 EOE RequestId=12780045-3ac2-11e7-8dc6-f7c2b766d8e7 global-action-trace=1278c342-3ac2-11e7-babe-0a5b00b90000 EOE']
答案 1 :(得分:0)
使用正则表达式:
<强>演示:强>
import re
s = """RequestId=159dd0dc-3ac2-11e7-9f57-b7548c7a91e2
global-action-trace=15a01af3-3ac2-11e7-babe-0a5b00b90000
EOE
RequestId=12780045-3ac2-11e7-8dc6-f7c2b766d8e7
global-action-trace=1278c342-3ac2-11e7-babe-0a5b00b90000
EOE"""
print(re.findall("RequestId=(.*)", s))
<强>输出:强>
['159dd0dc-3ac2-11e7-9f57-b7548c7a91e2', '12780045-3ac2-11e7-8dc6-f7c2b766d8e7']