Komarto Posted February 5, 2009 Share Posted February 5, 2009 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 More sharing options...
Authenticity Posted February 5, 2009 Share Posted February 5, 2009 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 More sharing options...
Komarto Posted February 5, 2009 Author Share Posted February 5, 2009 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 More sharing options...
BrettF Posted February 5, 2009 Share Posted February 5, 2009 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 Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 5, 2009 Share Posted February 5, 2009 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now