Skip to content

Instantly share code, notes, and snippets.

@UweRaabe
Created February 5, 2016 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UweRaabe/e0f41e8650eb53449afc to your computer and use it in GitHub Desktop.
Save UweRaabe/e0f41e8650eb53449afc to your computer and use it in GitHub Desktop.
RegEx-Test
program Project69;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.RegularExpressions,
System.Classes;
function FindMatches(const expression: string; const line: string; const options: TRegExOptions = [roExplicitCapture,roSingleLine]): TArray<string>;
var
regex: TRegEx;
index: integer;
matches: TMatchCollection;
begin
SetLength(Result, 0);
regex := TRegEx.Create(expression, options);
matches := regex.matches(line);
if matches.Count >= 1 then begin
SetLength(Result, matches.Count);
for index := 0 to matches.Count - 1 do
Result[index] := matches.Item[index].Value;
end;
end;
procedure Main;
var
arr: TArray<string>;
line: string;
lst: TStringList;
S: string;
begin
lst := TStringList.Create;
try
lst.Add('LIN+16++3773A081:BP''');
lst.Add('PIA+1+D:EC+DX000229:PO''');
lst.Add('IMD+F+8+:::ADAPTOR''');
for line in lst do begin
arr := FindMatches('[\+\:](\w|\s|\.|\-)*(?=[\+\:\''])', line);
for S in arr do begin
Writeln(S);
end;
end;
finally
lst.Free;
end;
end;
begin
try
Main;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment