Jump to content
Sign in to follow this  
ParoXsitiC

StringRegExp Help

Recommended Posts

ParoXsitiC

In 2006 this code use to work fine:

$sParamStr = "$testarray, $sub2,"
                $asParams = StringRegExp($sParamStr, '([^ ]*?[ ]?,)*', 3)

It would return this:

$asParams[0] = "$testarray,"

$asParams[1] = "$sub2,"

Now the latest stable, it returns this:

$asParams[0] = "$testarray,"

$asParams[1] = ""

---------------------

Can anyone explain to me what changed and what is going on?

Edited by ParoXsitiC

Share this post


Link to post
Share on other sites
ParoXsitiC

I changed the * to + and it works fine.

$asParams = StringRegExp($sParamStr, '([^ ]*?[ ]?,)*', 3) No work

$asParams = StringRegExp($sParamStr, '([^ ]*?[ ]?,)+', 3) Works

I found out the blank element is a NULL char.

Edited by ParoXsitiC

Share this post


Link to post
Share on other sites
ParoXsitiC

Bump. I am really curious what's going on here.

Share this post


Link to post
Share on other sites
Xenobiologist

Hi,

what do you want?

#include<Array.au3>
$sParamStr = "$testarray, $sub2,"
$asParams = StringRegExp($sParamStr, '\$.*?(?=,| )', 3)
_ArrayDisplay($asParams)

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
ParoXsitiC

Hi,

what do you want?

#include<Array.au3>
$sParamStr = "$testarray, $sub2,"
$asParams = StringRegExp($sParamStr, '\$.*?(?=,| )', 3)
_ArrayDisplay($asParams)

So long,

Mega

This is fine but the reason why he did it in such a weird way is because there is also support for Literals and not just params. Therefore a string may look like this:

$test, Function("test 2")

The $ is needed in the extracted so do that you can tell if its a parameter or a literal. Here is his complete code to get a better understand whats going on:

If $sParamStr <> "" Then
            If StringRight($sParamStr, 1) <> "," Then
                $sParamStr &= ","; Makes $sParamStr easier to parse with StringRegExp
            EndIf
            $asParams = StringRegExp($sParamStr, '(".*?".*?,|[^ ]*?[ ]?,)*', 3)
            If Not IsArray($asParams) Then
                SetError(2); Parameter string not formatted correctly
                Return -1; failure
            EndIf
            For $i = 0 To UBound($asParams) - 1
                If StringInStr($asParams[$i], "$") Then
                    $sStrippedParam = StringReplace(StringReplace($asParams[$i], "$", ""), ",", "")
                    If IsDeclared($sStrippedParam) Then
                        $vParamEval = Eval($sStrippedParam)
                        $sPackedParamStr &= _PackVarToStr($vParamEval)
                    Else
                        $sParamLiteral = StringTrimRight($asParams[$i], 1)
                        $sPackedParamStr &= _PackVarToStr($sParamLiteral)
                    EndIf
                Else
                    $sParamLiteral = StringTrimRight($asParams[$i], 1)
                    $sPackedParamStr &= _PackVarToStr($sParamLiteral)
                EndIf
            Next

Share this post


Link to post
Share on other sites
ParoXsitiC

Okay I am just going to assume that the + is the way it should be done and include it into the released UDF

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  

×