IsMatch(Text: String; [Pattern: String = "";] [StartPosition: Integer = 0]): Boolean;
Text. Input text, to which regular expression is applied.
Pattern. Regular expression template for checking.
StartPosition. Text position, from which checking starts.
The IsMatch method checks if text corresponds to the specified regular expression template.
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 returns True if text corresponds to the specified template, and False if text does not correspond to the specified template.
Sub UserProc;
Var
TelNumber: Array[5] Of String = [
"8-901-23-45678" ,
"+79012345678" ,
"+7(901)23-45678" ,
"7(901)2345678" ,
"8(902)34-56789" ];
Pattern: String = "(\+7|7|8)\(\d{3}\)\d{2}-\d{5}";
s: String;
Begin
Debug.WriteLine("Correspondence of telephone number to the X(XXX)XX-XXXXX template:");
For Each s In TelNumber Do
Debug.WriteLine(s + ": " + Regex.IsMatch(s, Pattern).ToString);
End For;
End Sub UserProc;
After executing the example the regular expression is used to check correspondence of telephone numbers to the specified template. Telephone numbers and checking results are displayed in the development environment console.
See also: