我在变量中有下面的字符串
'''
Messages Retrans Timeout Unexpected-Msg
INVITE ----------> 30 0 0
100 <---------- 30 0 0 0
180 <---------- 12 0 0 18
200 <---------- 12 0 0 0
ACK ----------> 12 0
INFO ----------> 12 0 0
200 <---------- 12 0 0 0
Pause [ 10.0s] 12 0
BYE ----------> 12 0
200 <---------- 12 0 0 0
'''
我如何才能得到下面的正则表达式匹配输出与一个模式或分钟模式。你知道吗
[('INVITE', '---------->', '30', '0', '0'), ('100', '<---------- ', '30', '0', '0', '0'), ('180', '<---------- ', '12', '0', '0', '18'), ('200', '<---------- ', '12', '0', '0', '0'), ('ACK', '---------->', '12', '0'), ('INFO', '---------->', '12', '0', '0'), ('200', '<---------- ', '12', '0', '0', '0'), ('BYE', '---------->', '12', '0'), ('200', '<---------- ', '12', '0', '0', '0')].
我使用了下面的脚本来获取输出。 +++++++++++++++++++++++++++++++++++++你知道吗
import re
aa = '''
xmlSFT_Client_mscmlivr MSCML_FULL_AUDIO_Script_CA_disabled.
Warning: open file limit > FD_SETSIZE; limiting max. # of open files to FD_SETSIZE = 1024
Resolving remote host '10.214.13.168'... Done.
------------------------------ Scenario Screen -------- [1-9]: Change Screen --
Call-rate(length) Port Total-time Total-calls Remote-host
10.0(0 ms)/1.000s 4063 11.24 s 30 10.214.13.168:5060(UDP)
Call limit reached (-m 30), 0.000 s period 0 ms scheduler resolution
0 calls (limit 300) Peak was 13 calls, after 1 s
0 Running, 31 Paused, 0 Woken up
0 dead call msg (discarded) 0 out-of-call msg (discarded)
2 open sockets
Messages Retrans Timeout Unexpected-Msg
INVITE ----------> 30 0 0
100 <---------- 30 0 0 0
180 <---------- 12 0 0 18
200 <---------- 12 0 0 0
ACK ----------> 12 0
INFO ----------> 12 0 0
200 <---------- 12 0 0 0
Pause [ 10.0s] 12 0
BYE ----------> 12 0
200 <---------- 12 0 0 0
'''
a = []
for i in aa.split('\n'):
if re.findall(r'^\s+(\w+)\s?(.-+.)\s+(\w+)\s+(\w+)\s+(\w+)\s+(\w+)',i,re.MULTILINE):
a.append(re.findall(r'^\s+(\w+)\s?(.-+.)\s+(\w+)\s+(\w+)\s+(\w+)\s+(\w+)',i,re.MULTILINE)[0])
elif re.findall(r'^\s+(\w+)\s?(.-+.)\s+(\w+)\s+(\w+)\s+(\w+)',i,re.MULTILINE) :
a.append(re.findall(r'^\s+(\w+)\s?(.-+.)\s+(\w+)\s+(\w+)\s+(\w+)',i,re.MULTILINE)[0])
elif re.findall(r'^\s+(\w+)\s?(.-+.)\s+(\w+)\s+(\w+)',i,re.MULTILINE):
a.append(re.findall(r'^\s+(\w+)\s?(.-+.)\s+(\w+)\s+(\w+)',i,re.MULTILINE)[0])
print a
+
所以首先,你的问题格式不好。我试着给你格式化,但你需要更多的文字来解释。你知道吗
基本上,根据我的理解,问题是有一个字符串
a
:你想要得到这样的结果:
('INVITE', ' >', '30', '0', '0'),
我使用以下正则表达式行来实现:
结果输出:
然后可以迭代
result_list
。你知道吗而不是像你在问题中提到的那样使用元组列表,因为我认为你可能想知道缺少了什么值。
('ACK', ' >', '12', '0')
这样可能不会告诉您缺少哪个2值,因为我在pause行看到只有message值和意外的msg值。Pause [ 10.0s] 12 0
希望这是你正在寻找的,请添加更多的问题描述,以便您可以很好地格式化您的代码。你知道吗
相关问题 更多 >
编程相关推荐