delphi 用正则表达式获取指定的字符串续取出所有符合要求的字符串

2018-10-31

function GetNextMatch(AValue, APattern: string): string;

var

  i: Integer;

  Regex: TRegex;

  s: string;

begin

  Regex := TRegex.Create(APattern, [roIgnoreCase]);

  for i := 0 to Regex.Matches(AValue).Count -1 do

    begin

      Result := Regex.Matches(AValue).Item[i].Value;

      GetNextMatch(Result, APattern);

    end;

end;

调用 GetNextMatch('begindklewjsabegindiekdjekdenickdkekkdiuiuijujenddkeidkkdend', '(?<=begin)([.\S\s]*)(?=end)');

结果:

    dklewjsabegindiekdjekdenickdkekkdiuiuijujenddkeidkkd,

    diekdjekdenickdkekkdiuiuijuj

阅读105