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

Compare with Current View Page History

Version 1 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 := StringReplace(match.Groups.Item[1].Value, '<br>', #13 + #10, [rfReplaceAll]);
  end else begin
    Result := '';
  end;
end;


  • No labels