Jump to content

Explanation needed


Recommended Posts

Hi,

sorry people, but I was trying to figure this out, but I've yet to understand what it does. Straight to the point:

1.

StringRegExp

The above line searches for a patern. The third, parameter,

Flag - [optional] A number to indicate how the function behaves. See below for details. The default is 0.
Flag - 1 Return array of matches.
Flag - 3 Return array of global matches.

I don't understand the differences between Flag 1 and 3. Written further:

Flag = 1 or 2 :
@Error Meaning 
0 Array is valid. Check @Extended for next offset 
1 Array is invalid. No matches. 
2 Bad pattern, array is invalid. @Extended = offset of error in pattern. 


Flag = 3 or 4 :
@Error Meaning 
0 Array is valid. 
1 Array is invalid. No matches. 
2 Bad pattern, array is invalid. @Extended = offset of error in pattern.

Can anyone give a good example how to use Flag 1 and 3? Both returns arrays of matches, however Flag one does something with @extended, how can I utilize the usage of @extended? Sorry, I just have trouble understanding, even experimenting didn't showed my understanding.

Thanks in advanced.

Regards,

Zepx

Link to comment
Share on other sites

  • Moderators

Flag 1 only returns the first match found, so the array would be how ever many queries you told it to make in the first match found.

Example:

Local $sStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
Local $aSRE = StringRegExp($sStr, "(?i)abcd(.+?)ghijklmn(.+?)rstu(.+?)z", 1)

Would return:

[0] = EF

[1] = OPQ

[2] = VWXY

When

Local $sStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
Local $aSRE = StringRegExp($sStr, "(?i)abcd(.+?)ghijklmn(.+?)rstu(.+?)z", 3)

Would return:

[0] = EF

[1] = OPQ

[2] = VWXY

[3] = ef

[4] = opq

[5] = vwxy

Edited by SmOke_N
** forgot to tell it to search $sStr :doh:

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Thanks for the explanation on that, then what about the @extended? How can I utilize it's usage?

I've never played with @extended in StringRegExp(), but I would imagine that would mean a pointer to the char number (number of characters in the string) where the pattern failed.

----------1---------2
123456789012345678901234567
I am an expression that you wrote

Lets say @extended returns 11, then that would tell us (If I understand it right) that the error started at "p".

That is unless it's zero based, then 11 would equal "r".

Don't take the above as gospel, I'm just telling you how I see it.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thanks for the explanation on that, then what about the @extended? How can I utilize it's usage?

Only if you get an error. If the @error code indicates a bad pattern, then @extended will (sort of) give the character position in the pattern where the error was detected.

Here is SmOke_N's RegExp with some error detection and display added:

#include <Array.au3>; Only for _ArrayDisplay()

Local $sStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
Local $sSRE = "(?i)abcd(.+?)ghijklmn(.+?)rstu(.+?)z"; Good pattern

_DoRegExp($sStr, $sSRE); Works

$sSRE = "(?i)abcd\(.+?)ghijklmn(.+?)rstu(.+?)z"; Bad pattern

_DoRegExp($sStr, $sSRE); Fails

Func _DoRegExp($sString, $sExpression)
    Local $avRET = StringRegExp($sString, $sExpression, 1)
    If @error = 0 Then
        _ArrayDisplay($avRET, "Debug: Success")
    Else
        MsgBox(16, "Error", "@error = " & @error & "  @extended = " & @extended)
    EndIf
EndFunc  ;==>_DoRegExp

The "\(" is invalid in the pattern, causing the second one to fail. The value returned in @extended tells you where the error is. I said "sort of" before because it's the position of the LAST character in the offending group (or "ATOM" in PCRE-speak, I think). So the "\" gets inserted at position 9, but @extended shows the error at 14 because that's the end of the failed "\(.+?)" portion.

Hope that helps.

:)

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...