RegEx help

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
JBurger
Junior Coder
Posts: 33
Joined: Wed Nov 12, 2003 7:16 pm
Location: NY

RegEx help

Post by JBurger » Tue May 12, 2009 6:16 pm

I've been trying to understand the Regex in MS.

I have some text in a file

Code: Select all

May 12 2009 11:30:38
Temp pH   ORP  
79.0 8.00 427  
 CRX is ON  Auto
 KRX is OFF Auto
 OZN is OFF Auto
 HET is OFF Auto
 TPF is ON  Auto
 RFG is OFF Auto
 VOD is OFF Manual
 PMP is OFF Auto
 FPH is ON  Auto
 FMH is OFF Manual
 COL is OFF Auto
 MHL is OFF Auto
 MHC is OFF Auto
 MHR is OFF Auto
 VHO is ON  Auto
 SW1 is OFF Auto
 SW2 is OFF Auto
 MNT is OFF Auto
 VPH is OFF Auto
 ALM is OFF Auto
 PH1 is PF3 Auto
 PH2 is PF4 Auto
Power Failed: None
Power Restored: None
In my example I just want to find out the status of MHR if it is ON or OFF

Using regex that works for me in the past even the simple expression
MHR (.*.) Auto
gives me back the MHR line and everything after. I just need to capture the line or really just the ON or OFF status.

Here is what I am using right now

Code: Select all

Let>Pattern=MHR (.*.) Auto
Regex>%Pattern%,%var%,0,mres,num,0
Let>X=%mres_1%
Where var is the text info in the first section.

Any help would be great!

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Try this regex

Post by gdyvig » Wed May 13, 2009 2:56 pm

Hi JBurger,

I am new to regex also. Don't understand what the parens are for.

However. this works:

Let>Pattern=MHR is O[NF][F ]*Auto
Regex>%Pattern%,%var%,0,mres,num,0
Let>X=%mres_1%
MDL>(%X%)

Let>Pattern2=O[NF][F ]
Regex>%Pattern2%,%X%,0,mres2,num,0
Let>IGNORESPACES=1
Let>OnOff=%mres2_1%

MDL>(%OnOff%)


Gale

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed May 13, 2009 3:32 pm

Or:

Code: Select all

Let>file=%USERDOCUMENTS_DIR%\stats.txt
ReadFile>file,data
Let>pattern=(?<=MHR is\s*)(ON|OFF)(?=\s*Auto)
RegEx>pattern,data,0,matches,num_matches,0
if>num_matches>0
  MessageModal>status=%matches_1%
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts