Jump to content

RegEx Array gone crazy?


Komarto
 Share

Recommended Posts

Hi,

I am new to autoit and i tried testing the regex match

opt("TrayIconDebug", 1)

    $Array = StringRegExp ( "<test>Tal1</test><test>Tal2</test><test>Tal3</test><test>Tal4</test>", "<(?i)test>(.*)</test><test>(.*)</test><test>(.*)</test><test>(.*)</test(i?)>" ,  1, 1)

    msgbox(0, "Test", UBound($Array)-1)


    for $i = 0 to UBound($Array)-1; I suppose to have 4 loops, why am i getting 5?
        msgbox(0, "RegExp Test with Option 1 - " & $i, $array[$i])
    Next

I used a regex match and i am suppose to have only 4 loops (as showed by the msgbox), But the loop runs 5 times (I get an empty msgbox).

Why is this happening?

Thanks

komar

Link to comment
Share on other sites

You're lucky it's only 5 - (.*) means match any char which is not a new line (default option) at least 0 or more times so it can be nothing also lol. Try reading not only the help file's explanation of StringRegExp behavior but also the short tutorial under 'String Regular expression' and use the bottom application for testing purpose...

Link to comment
Share on other sites

You're lucky it's only 5 - (.*) means match any char which is not a new line (default option) at least 0 or more times so it can be nothing also lol. Try reading not only the help file's explanation of StringRegExp behavior but also the short tutorial under 'String Regular expression' and use the bottom application for testing purpose...

But its suppose to capture any charecter between the test tags, even if the tag is empty, right?

If so i suppose to get 4 matches, and if i am using ubound -1 i need to get 4 loop and no extra loop with an empty msgbox.

can someone explain the extra loop?

Link to comment
Share on other sites

Try this:

Opt("TrayIconDebug", 1)

$Array = StringRegExp("<test>Tal1</test><test>Tal2</test><test>Tal3</test><test>Tal4</test>", "<(?i)test>(.*?)</(?i)test>", 3, 1)

MsgBox(0, "Test", UBound($Array) - 1)


For $i = 0 To UBound($Array) - 1; I suppose to have 4 loops, why am i getting 5?
    MsgBox(0, "RegExp Test with Option 1 - " & $i, $Array[$i])
Next

Cheers,

Brett

Link to comment
Share on other sites

This was what I came up with to do the same:

#include <Array.au3>

$RET = StringRegExp("<test>Tal1</test><test>Tal2</test><test>Tal3</test><test>Tal4</test>", "(?:<test>)(.*?)(?:</test>)", 3)
$iErrSav = @error
$iExtSav = @extended
If IsArray($RET) Then
    _ArrayDisplay($RET, "$RET")
Else
    ConsoleWrite("Error = " & $iErrSav & "  Extended = " & $iExtSav & @LF)
EndIf

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...