#1
|
|||
|
|||
Reading Output and Filter it with Regular Expression
I try to filter the output of my command. I read it in into a variable and after that filter the output with the regular expression. But the regular expression does not work. I tried a lot of different ones....
This is the Output: Product: C10G, System Uptime:145 d, 11 h, 27 m, 59 s Chassis Serial No: N/A System Time: Mon Sep 26 13:07:31 ICT 2016 128MHz, 5 PPM Crystal Clock Module 6, Master SMM_2x10G, Status ACTIVE Major rev 1, Minor rev 8 serial_no = SB15BCAS0032 CFE version 12.4.11 Uptime: 48 d, 5 h, 53 m, 3 s Module 7, Slave SMM_2x10G, Status STANDBY Major rev 1, Minor rev 8 serial_no = SB15BC7S0042 CFE version 12.4.11 Uptime: 45 d, 21 h, 9 m, 8 s This is what I want to filter and write to my file: "Uptime: **d" of Module 6 (red in the text above) This is my current code: Code:
Set file to write... Set re1 = New RegExp re1.Pattern = "Module 6,[\s+\S+]*(Uptime:s\d+)[\s+\S+]*Module 7," strResult = crt.Screen.ReadString("Module 13") 'Filter with Regular Expression Set matches = re1.Execute(strResult) For each match in matches match1 = match.submatches(0) next strSerial = match1 objFile.Write strSerial & "," What is wrong with my regular expression or the submatching? Thank you |
#2
|
|||
|
|||
Hi Mali,
I've spotted a few issues. For one thing you are capturing via ReadString() until Module 13 is received and at least in the sample output you posted, there is not a Module 13. I assume you truncated the output. ![]() The first thing I would suggest is you put in a MsgBox() line to show strResult to make sure it at least has the output you need to capture. Secondly, do you really *only* want Module 6's output? If so, there were a few problems with the regular expression. I had success with this string: re1.Pattern = "Module 6,[\s\S]+?(Uptime:\s\d+\sd)" You don't need to handle what comes after the desired capture string. If your ultimate goal is to capture uptime for more than one module, then you need to make some additions to your code. What are your results if you incorporate the above suggestions?
__________________
Thanks, --Brenda VanDyke Software Technical Support support@vandyke.com (505) 332-5730 |
![]() |
Tags |
filtering , regular expression |
Thread Tools | |
Display Modes | Rate This Thread |
|
|