IRegex.Match

Syntax

Match(Text: String; [Pattern: String = "";] [StartPosition: Integer = 0]): IRegexMatch;

Parameters

Text. Input text, to which regular expression is applied.

Pattern. Regular expression template for checking.

StartPosition. Text position, from which regular expression is started to be checked.

Description

The Match method gets result of comparing the specified text with the regular expression.

Comments

The regular expression is set as a string that corresponds to regular expression standard determined in the ECMAScript language. For details see various resources devoted to this language, for example, en.cppreference.com, cplusplus.com. The method results in the information about found correspondences with single groups of the specified regular expression template.

Example

Sub UserProc;
Var
    SourceText: String = "Example of component use is given in the chapter 1.2.3.4.";
    Pattern: String = "in the chapter (\d+(\.\d)*)";
    Result: IRegexMatch;
    s: String;
Begin
    Result := Regex.Match(SourceText, Pattern);
    If Result.Success Then
        Debug.WriteLine("Index of position of the first found value: " + Result.Index.ToString);
        // Array of rows containing correspondences to template groups
        For Each s In Result.Group Do
            Debug.WriteLine(s);
        End For;
    End If;
End Sub UserProc;

After executing the example the regular expression is applied to the specified text to get the chapter number. The operation results in following values:

Unit execution started

Index of position of the first found value: 41

in the chapter 1.2.3.4

1.2.3.4

.4

Unit execution finished

The first value "in the chapter 1.2.3.4" corresponds to the entire regular expression, the value "1.2.3.4" is taken by the (\d+(\.\d)*) group, the last value ".4" corresponds to the (\.\d) group.

See also:

IRegex