Python Forum
python3 regular expression.. support to improve
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python3 regular expression.. support to improve
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  data validation with specific regular expression shaheen07 0 329 Jan-12-2024, 07:56 AM
Last Post: shaheen07
  Regular Expression search to comment lines of code Gman2233 5 1,660 Sep-08-2022, 06:57 AM
Last Post: ndc85430
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 1,661 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
  Need help with my code (regular expression) shailc 5 1,920 Apr-04-2022, 07:34 PM
Last Post: shailc
  Regular Expression for matching words xinyulon 1 2,164 Mar-09-2022, 10:34 PM
Last Post: snippsat
  regular expression question Skaperen 4 2,475 Aug-23-2021, 06:01 PM
Last Post: Skaperen
  How can I find all combinations with a regular expression? AlekseyPython 0 1,669 Jun-23-2021, 04:48 PM
Last Post: AlekseyPython
  Python Regular expression, small sample works but not on file Acernz 5 2,921 Jun-09-2021, 08:27 PM
Last Post: bowlofred
  Regular expression: cannot find 1st number in a string Pavel_47 2 2,412 Jan-15-2021, 04:39 PM
Last Post: bowlofred
  Regular expression: return string, not list Pavel_47 3 2,491 Jan-14-2021, 11:49 AM
Last Post: Pavel_47

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020