Example, RegEx Array vs Pseudo Array

Helpful script writing tricks and HowTo's
tripshack
Posts: 7
Joined: 26 Nov 2014, 23:21

Example, RegEx Array vs Pseudo Array

02 Dec 2014, 23:43

I wrote this example while learning about RegEx and how it works in AHK.
The Match Object vs Pseudo array output was very confusing until I saw what was going on.
This may be mentioned in the docs, but not exactly stated outright.



Code: [Select all] [Expand] [Download] (Script.ahk)GeSHi © Codebox Plus



*Corrected references to "Array" which should be "Object Match" per Lexikos comments below, thanks.
**Corrected references to "Object Match" which should be "Match Object" per Lexikos comments below, thanks :)
Last edited by tripshack on 22 Dec 2014, 23:00, edited 3 times in total.
lexikos
Posts: 6130
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Example, RegEx Array vs Pseudo Array

22 Dec 2014, 01:59

It's not an array. It's a Match Object.
Mode 3 (match object) [v1.1.05+]: If a capital O is present in the RegEx's options -- such as "O)abc.*123" -- a match object is stored in UnquotedOutputVar. This object can be used to retrieve the position, length and value of the overall match and of each captured subpattern, if present.
Match Object
If a capital O is present in the RegEx's options, a match object is stored in UnquotedOutputVar. This object has the following properties:

Match.Pos(N): Returns the position of the overall match or a captured subpattern.
Match.Len(N): Returns the length of the overall match or a captured subpattern.
Match.Value(N): Returns the overall match or a captured subpattern.
Match.Name(N): Returns the name of the given subpattern, if it has one.
Match.Count(): Returns the overall number of subpatterns.
Match.Mark(): Returns the NAME of the last encountered (*MARK:NAME), when applicable.

Match[N]: If N is 0 or a valid subpattern number or name, this is equivalent to Match.Value(N). Otherwise, N can be the name of one of the above properties. For example, Match["Pos"] and Match.Pos are equivalent to Match.Pos() unless a subpattern named "Pos" exists, in which case they are equivalent to Match.Value("Pos").

Match.N: Same as above, except that N is an unquoted name or number.

For all of the above properties, N can be any of the following:
  • 0 for the overall match.
  • The number of a subpattern, even one that also has a name.
  • The name of a subpattern.

Brackets [] may be used in place of parentheses () if N is specified.
tripshack
Posts: 7
Joined: 26 Nov 2014, 23:21

Re: Example, RegEx Array vs Pseudo Array

22 Dec 2014, 13:03

lexikos wrote:It's not an array. It's a Match Object.


Thanks. Match Object is the correct term to use. I'll fix that in the original post.
lexikos
Posts: 6130
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Example, RegEx Array vs Pseudo Array

22 Dec 2014, 20:56

Object Match != Match Object. ;)
tripshack
Posts: 7
Joined: 26 Nov 2014, 23:21

Re: Example, RegEx Array vs Pseudo Array

22 Dec 2014, 23:02

lexikos wrote:Object Match != Match Object. ;)


Oops. Fixed.

Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 5 guests