Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-28-2016, 12:19 AM
Mali Mali is offline
Registered User
 
Join Date: Oct 2016
Posts: 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 & ","
Capturing the Output does work, I have already testet it. And i dont get an error for setting the match1 = match.submatches(0). So it seems to be not "null"

What is wrong with my regular expression or the submatching?

Thank you
Reply With Quote
  #2  
Old 10-28-2016, 12:12 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
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
Reply With Quote
Reply

Tags
filtering , regular expression

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 11:07 AM.