Python Forum

Full Version: python3 regular expression.. support to improve
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,

I am parsing below logs lines, regex is working, checked on online regex editor(https://regex101.com/), please lets know any suggestion.



Working regex (re.search)
------------------
CAM ID or CAM Id --- (\b\s\:\s)(\d.*?)\b\, --- group(2)

e.g. CAM ID: 19378780 or CAM Id : 3835407
here able to capture 'CAM Id : 3835407' as this end with , and not 'CAM ID: 19378780(' as this ends with '('
sample :- CAM ID: 19378780(A1-VC4-Snk-5 : TU12-Snk-1-2-2 ),

-------------------

Native or native cause --- \s([\w+]{6}\s\w...)\s(\w.*)\b, --- group(2)
e.g. native P.C: LP-EXC, and Native P.C: BIT Failed,

-------------------

system time --- (\d./\d./\d.\s\d.:\d.:\d.) --- group(1)
e.g.[24236:20 04/07/20 13:03:41 InternalExternalAlarmList.cc:55]

-------------------

Port --- \((.*?)\) --- group(1)
here facing issue, sometime string with one opening '(' and end with double '))', and wanted '(' captured in regex.

eg. (XS B:SAM_16 oPort 1-SFP)) or (XS B:SAM_16 oPort 1-SFP ))

-------------------

Nodename --- \b\/([A-Z]{3}?.\w.*?)\b@ --- group(1)
here not able to capture like 'EMS_BG-40_17', how can i capture like EMS~~LSN/EMS_BG-40_17
-------------------

Alarm Status --- (<?[a-zA-Z0-9_ ]+>)\s(.*?\b\s) --- group(2)
Capturing only New or Clear.

e.g. [24236:20 04/07/20 13:03:41 InternalExternalAlarmList.cc:55] > Clear
[1833:22 01/07/20 14:08:25 InternalExternalAlarmList.cc:287] > New

-------------------

logs:
=======


[24236:20 04/07/20 13:03:41 InternalExternalAlarmList.cc:55] > Clear to Alarm was reported on : EMS~~LSN/EMS_XDM_13@@ManagedElement~~12338@@PTP~~4:4@@CTP~~/sts3c_au4-j=1/vt2_tu12-k=1-l=2-m=2 CAM ID: 19378780(A1-VC4-Snk-5 : TU12-Snk-1-2-2 ), P.cause 4, native P.C: DEG, rate : 11 and Qualifier : 106@@65535@@29 EMS time: 20200704131151.0
[24236:20 04/07/20 13:03:41 InternalExternalAlarmList.cc:55] > Clear to Alarm was reported on : EMS~~LSN/EMS_BG-40_17@@ManagedElement~~9365@@PTP~~/shelf=1/slot=5/ebtype=SAM4_2/port=2@@CTP~~/sts3c_au4-j=3/tu3_vc3-k=1 CAM ID: 18843134(BS:SAM4_2 oPort 2-VC4#3VC3#1), P.cause 0, native P.C: LP-EXC, rate : 13 and Qualifier : 9365@@4@@-1@@-1@@-1@@-1@@-1@@7@@6@@5@@0@@3@@1@@622 EMS time: 20200701113454.0
[24236:20 04/07/20 13:03:41 InternalExternalAlarmList.cc:55] > Clear to Alarm was reported on : EMS~~LSN/EMS_BG-40_17@@ManagedElement~~4489@@PTP~~/shelf=1/slot=6/ebtype=SAM-16/port=1 CAM ID: 19378845(XS B:SAM_16 oPort 1-SFP), P.cause 11, native P.C: RX-oPower-Low, rate : 22 and Qualifier : 4489@@5@@-1@@-1@@-1@@-1@@-1@@-1@@-1@@34@@0@@3@@0@@610 EMS time: 20200704130709.0
[1833:22 01/07/20 14:08:25 InternalExternalAlarmList.cc:287] > New Alarm was reported on : EMS~~LSN/EMS_XDM_91@@ManagedElement~~4436@@EquipmentHolder~~/rack=1/shelf=1/slot=18@@Equipment~~1 ( F1-xFCU ) with CAM Id : 3835407, P.cause 11, Native P.C: BIT Failed, rate : 1 and Qualifier : 516@@65535@@2 EMS time: 20200701140321.0