Description
The RegExpr.ExecPos
method searches the input string starting from the AOffset position for the text that matches the regular expression pattern. To get a portion of the text that matches the pattern use the Match
property.
Declaration
RegExprObj.ExecPos(AOffset)
RegExprObj | An expression, variable or parameter that specifies a reference to a RegExpr object | |||
AOffset | [in] | Optional | Integer | Default value: 1 |
Result | Boolean |
Applies To
The method is applied to the following object:
Parameters
The method has the following parameter:
AOffset
An integer specifying the input string character position where the search operation started.
Result Value
Returns True if the text matching the expression was found and False otherwise.
Remarks
You should initialize the Expression
property with the regular expression and the InputString
property (explicitly or implicitly via previous Exec
call) with the input string before calling the ExecPos
method, otherwise an error occurs.
Example
The following example demonstrates how you can use the RegExpr.ExecPos
method to specify whether the input string that starts from the specified position contains the text that matches the pattern.
DelphiScript
var
MyRegExpr: OleVariant;
Input, Expr: string;
begin
MyRegExpr := HISUtils.RegExpr;
Input := 'TestComplete project suite files have the .pjs extension.';
// This expression specifies the extension pattern
Expr := '(\.[\w]+)';
MyRegExpr.InputString := Input;
MyRegExpr.Expression : = Expr;
// Checks whether the input string contains matching text after the specified position
if MyRegExpr.ExecPos(40) then
Log.Message('The matching text is found after the specified position')
else
Log.Message('No matching text was found after the specified position');
end;
See Also
Regular Expressions Syntax
Using Regular Expressions in Scripts
Expression Property
InputString Property
Match Property
Exec Method
ExecNext Method