You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

TRegEx is a useful class for regular expression. You can define a instance with a regular expression, and match the case by TMatch.Following is a example to search XML tag by TRegEx and TMatch

uses System.RegularExpressions

.
.
.

function getXMLTagValue(source, tag:string):string;
var
  mRegExp: TRegEx;
  match: TMatch;
begin
  mRegExp := TRegEx.Create( '<' + tag + '>(.*)</' + tag + '>', [roIgnoreCase,roMultiline]);
  match := mRegExp.Match( source);
  if match.Success then
  begin
    Result := match.Groups.Item[1].Value;
  end else begin
    Result := '';
  end;
end;
  • No labels