Jump to content
Sign in to follow this  
Quual

Need help with a complicated Reg Expression

Recommended Posts

Quual

I'm writing a small program to clean up a script by removing various things from the file. having trouble with ConsoleWrite() Lines

I have this and it works great except for one problem,

While True
    $vRet = StringRegExp($sContents, "\n(.*?ConsoleWrite(?P<po>\(((?>[^()]+)|(?P>po))*\)).*?)\r",1,$nOffset)
        If @error Then
            ExitLoop 
        Else
            $nOffset = @extended
        EndIf
        $vTaskfin[0] += 1; just a counter of lines removed
        $sOut = StringReplace($sOut, @LF & $vRet[0] & @CR,"",1)
    WEnd

The problem is if there is a single ( or ) inside a quoted 'string' the reg ex misses the line. I'm just not having any luck getting the recursive search to ignore a single ( or ) inside a quoted string.

I could do it with a loop and some StringInStr and StringTrim functions, however I'm annoyed that I can't get the reg exp working.

And for serious bonus points : a pattern that works with StringRegExpReplace($sContents,$pattern,"") , so I can get rid of the StringReplace Line. (I'm not even sure that it is possible.)

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  

×