How to find all double quote substrings in a string with Pascal

1 Answer

0 votes
program ExtractDoubleQuoteSubstrings;

uses
  RegExpr;

var
  strValue: string;
  regex: TRegExpr;
begin
  strValue := 'This is a string with "double-quoted substring1", and "double-quoted substring2" inside.';

  // Initialize and configure regex pattern
  regex := TRegExpr.Create;
  
  regex.Expression := '"([^"]*)"'; // Regular expression to match substrings within double quotes

  // Execute regex search
  if regex.Exec(strValue) then
  begin
    repeat
      // Print extracted substring
      Writeln(regex.Match[1]);
    until not regex.ExecNext;
  end;
  
  // Free regex object to prevent memory leaks
  regex.Free;
end.



  
(*
run:
  
double-quoted substring1
double-quoted substring2
  
*)

 



answered May 13 by avibootz
...