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