|
|
 |
MatchInfo Table
The matchInfo table is a descriptive table containing information about the match of a regular expression against a target object. It will be constructed by the regex engine in two cases:
- The verbs regex.match, regex.easyMatch, regex.search, and regex.easySearch will populate a matchInfo table at a specified address if that address is included in the parameters passed to the verbs. Since these verbs return only true or false - indicating whether the match was successful or not, a matchInfo table allows information about the nature of the match to be examined.
- The verbs regex.subst and regex.visit both (optionally) take the address of a callback script. These callback scripts are required to take the address of the matchInfo table as one of their parameters.
The matchInfo table always contains the following information about the match:
- matchString
-
The string that matches the pattern.
- matchOffset
-
The position in the target string where the pattern commenced.
- matchLength
-
The number of characters in the target string match for the pattern.
The matchInfo table optionally contains the following information about matched subpatterns if the makeGroups parameter is true.
- groupStrings
-
A list whose elements are the strings that matched any subpatterns.
- groupOffsets
-
A list whose elements are the positions in the target
string where the subpatterns commence.
- groupLengths
-
A list whose elements are the lengths of the strings matching the subpatterns.
The following is an example of a matchInfo table from a search for the subject field in an email message. The email message is contained in the string variable s.
regex.easySearch ("(Subject:) +([^\r]*)\r", s, @temp.matchInfo)
|
 |