Description
The RegExpr.MatchLen
property returns the length of the text that matches a regular expression or its sub-expression. The index specifies whether the text suits a whole expression or only a sub-expression. The total number of found sub-expressions is specified by the SubExprMatchCount
property.
Declaration
RegExprObj.MatchLen(Index)
Read-Only Property | String |
RegExprObj | An expression, variable or parameter that specifies a reference to a RegExpr object | |||
Index | [in] | Required | Integer |
Applies To
The property is applied to the following object:
Parameters
The property has the following parameter:
Index
Specifies the item’s index. The text that matches the whole expression has an index of 0, part of the text that matches the first sub-expression - 1, and so on.
Property Value
The length of the matching text.
Remarks
If the specified index does not exist or the sub-expression was not found this property returns -1.
Example
The following example demonstrates how you can use the RegExpr.MatchLen
and RegExpr.MatchPos
properties to obtain the length and position of the matching text.
DelphiScript
var
MyRegExpr : OleVariant;
Input, Expr, ResStr, Info : string;
begin
MyRegExpr := HISUtils.RegExpr;
Input : = 'Please e-mail us at [email protected] or [email protected]';
// Specifies an e-mail address pattern
Expr := '[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}';
MyRegExpr.Expression : = Expr;
if MyRegExpr.Exec(Input) then
begin
repeat
begin
// Posts the matching text, its length and position in the input text to the test log
Info := '';
ResStr := MyRegExpr.Match[0];
Info := 'A match is found at position ' + aqConvert.IntToStr(MyRegExpr.MatchPos[0]);
Info := Info + #13 + 'The matching fragment length is ' + aqConvert.IntToStr(MyRegExpr.MatchLen[0]);
Log.Message(ResStr, Info);
end;
until not MyRegExpr.ExecNext;
end;
end;
See Also
Using Regular Expressions in Scripts
Using Regular Expressions in Scripts
Exec Method
SubExprMatchCount Property
Match Property
MatchPos Property