Jump to content
Sign in to follow this  
cvocvo

StringRegExp and StringRegExpReplace Help

Recommended Posts

cvocvo

I need some help with StringRegExp and StringRegExpReplace in parsing the output (STDOUT, but using $STDERR_MERGED) of fbwfmgr.

Enabled Output:

Posted Image

Disabled Output:

Posted Image

In the enabled output picture I need to use StringRegExpReplace to replace the "Filter State: Enabled" under "next session:" with "Filter State: Disabled".

In the disabled output picture I need to be able to read (into a variable) the "filter state: disabled" text that follows "current session:" and I need to read (into a variable) the "filter state: enabled" text that follows "next session:". The tricky part here is that I basically just need to read the line below current session and next session into variables, and the "filter state: " portion can be enabled or disabled for both.

I've tried to accomplish this with using StringSplit with @CRLF's and it doesn't seem to split the lines up for some reason, and I've also tried to use StringInStr but that didn't work because I couldn't get it to search over multiple lines of characters for the character limit. I tried using StringRegExp with '(next session:)\s(filter state:)\s[:alnum:], but I don't understand it enough to get it to work.

If there are any ninja's of StringRegExp and StringRegExpReplace out there that could help, I'd appreciate it. Thanks

Edited by cvocvo

Share this post


Link to post
Share on other sites
ShawnW

totally untested but this might work.

For the replacement of enabled with disabled after next session...

StringRegExpReplace($output,"(?-m)(next session:\s+filter state: )enabled.","\1disabled.")

And for getting the values of filter state on bot sections into variables use this...

$matches = StringRegExp($output,"filter state: (.+)\.",1)

$matches will be an array where the 1st element is the current session 'enabled' or 'disabled', and the 2nd element is the next session.

Share this post


Link to post
Share on other sites
cvocvo

Thanks for the help, but those didn't work. I tested with a messagebox and got a blank messagebox for the StringRegExp and the StringRegExpReplace.

I sent the output to a txt file, here's the output for fbwfmgr:

File-based write filter configuration for the current session:
    filter state: disabled.

File-based write filter configuration for the next session:
    filter state: enabled.
    overlay cache data compression state: enabled.
    overlay cache threshold: 256 MB.
    overlay cache pre-allocation: disabled.
    size display: actual mode.
    protected volume list:
      \Device\HarddiskVolume2
    write through list of each protected volume:
      \Device\HarddiskVolume2:
        \Windows\bootstat.dat
        \Windows\System32\spool
        \Windows\Prefetch
        \Windows\Debug\Usermode
        \pagefile.sys
        \temp

Also, here is the code I'm using to get the output from fbwfmgr:

$fbwfmgr = Run(@ComSpec & " /c fbwfmgr", "", @SW_HIDE, $STDERR_MERGED) ;;getstatus
    While 1
        $Status &= StdoutRead($fbwfmgr)
        If @error Then ExitLoop
    Wend
    MsgBox(0, "The output is:", $Status)

Share this post


Link to post
Share on other sites
ShawnW

Ok I said it returns an array. You cannot just display an array in a message box without referencing the variable index. I did make 1 mistake though and the flag is 3 not 1. Here is some code I tested and seems to work. I pasted the example into a text file test.txt and read that for input. It gives 2 message boxes 1 reading the 2 states current and next. The 2nd is an output of the replace function that displays the entire string returned. You will notice that the enabled in the next section has been changed.

#include <array.au3>
$output = FileRead("test.txt")
; Gets current and next filter states
$matches = StringRegExp($output,"filter state: (.+)\.",3)
If @error Then
    MsgBox(0,"Error",@error)
Else
    _ArrayDisplay($matches)
EndIf

$output = StringRegExpReplace($output,"(?-m)(next session:\s+filter state: )enabled.","\1disabled.")
If @error Then
    MsgBox(0,"Error",@error)
Else
    MsgBox(0,"Output",$output)
EndIf

Share this post


Link to post
Share on other sites
cvocvo

Ah, my oversight there.

Thank you for the help -- works great!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×