program RegexMatch;
uses
RegExpr;
var
Regex: TRegExpr;
TestStrings: array[0..4] of string = ('http', 'htttp', 'httttp', 'httpp', 'htp');
i: Integer;
begin
// Initialize regex pattern
Regex := TRegExpr.Create;
Regex.Expression := 'htt+p'; // Equivalent to Python's r"htt+p"
// Check matches
for i := Low(TestStrings) to High(TestStrings) do
begin
if Regex.Exec(TestStrings[i]) then
WriteLn('Matches "', TestStrings[i], '": true')
else
WriteLn('Matches "', TestStrings[i], '": false');
end;
Regex.Free; // Free memory
end.
// Matches "httpp": True or false, depending on how matches() method works
(*
run:
Matches "http": true
Matches "htttp": true
Matches "httttp": true
Matches "httpp": true
Matches "htp": false
*)