I have seen several Delphi examples of TRegEx
usage like the following one in Delphi 10.1.2:
try
RegexObj := TRegEx.Create(REGEX_EXTRACTEMAILADDRESSES, [roIgnoreCase]);
MatchResults := RegexObj.Match(ThisPageText);
while MatchResults.Success do
begin
slEmailAddressesOnThisPage.Add(MatchResults.Value);
MatchResults := MatchResults.NextMatch();
end;
except
on E: ERegularExpressionError do
begin
// Todo: Log Syntax error in the regular expression
end;
end;
So I wonder whether the TRegEx
object must be explicitly freed after creation in such an example?
The Match-zero-or-more Operator ( * ) This operator repeats the smallest possible preceding regular expression as many times as necessary (including zero) to match the pattern. `*' represents this operator. For example, `o*' matches any string made up of zero or more `o' s.
Regular expressions are particularly useful for defining filters. Regular expressions contain a series of characters that define a pattern of text to be matched—to make a filter more specialized, or general. For example, the regular expression ^AL[.]* searches for all items beginning with AL.
Using character sets For example, the regular expression "[ A-Za-z] " specifies to match any single uppercase or lowercase letter. In the character set, a hyphen indicates a range of characters, for example [A-Z] will match any one capital letter.
Only class objects that derive from TObject
must be explicitly freed from memory after being created. TRegEx
is a record
instead, so it is released when it goes out of scope. TRegEx.Create
is a constructor, but not one that creates a new object on the heap, just on the call stack, so there is nothing to free manually (there is no destructor defined for it).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With