输入字符串:-
r="""Jun 5 13:09:36.132: %ASESDK-5-NOTICE: dcmd[6670] 879 libloadindexmapmanager.ResilienceStatusEventHandler: uid=[1804108988984000615]userplaneFullyResilient: User plane resilience alarm cleared in 899 seconds, affected users 0 (1)...
Jun 5 13:09:36.132: %ASESDK-5-NOTICE: dcmd[6670] 879 libloadindexmapmanager.ResilienceStatusEventHandler: .333252 (2)"""
必需的输出:-
r="""Jun 5 13:09:36.132: %ASESDK-5-NOTICE: dcmd[6670] 879 libloadindexmapmanager.ResilienceStatusEventHandler: uid=[1804108988984000615]userplaneFullyResilient: User plane resilience alarm cleared in 899 seconds, affected users 0.333252 """
答案 0 :(得分:0)
我认为您想做这样的事情:
import re
regex = r"(.*) \(1\)(.*): (.*) "
new_string = ""
test_str = "Jun 5 13:09:36.132: %ASESDK-5-NOTICE: dcmd[6670] 879 libloadindexmapmanager.ResilienceStatusEventHandler: uid=[1804108988984000615]userplaneFullyResilient: User plane resilience alarm cleared in 899 seconds, affected users 0 (1)... Jun 5 13:09:36.132: %ASESDK-5-NOTICE: dcmd[6670] 879 libloadindexmapmanager.ResilienceStatusEventHandler: .333252 (2)"
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
new_string = (match.group(1) + match.group(3))
print (new_string)
输出为:
Jun 5 13:09:36.132: %ASESDK-5-NOTICE: dcmd[6670] 879 libloadindexmapmanager.ResilienceStatusEventHandler: uid=[1804108988984000615]userplaneFullyResilient: User plane resilience alarm cleared in 899 seconds, affected users 0.333252