i thought about that, too.
Caveat: It works as long as there is a double-quote, though i'm aware that in my case the Regex would fail, too.
But adjusting the Regex-Expression is simple, nevermind, that with regex you could even split/extract further information from the string.
Ah well.... as always in life: Many ways to skin a cat
adjusted RegEx-Pattern = (\d+?)\s+("{,1}.+"{,1})
Finds now both variants: w/o doublequotes
EDIT: Crap. I tested above adjusted pattern online, not in FPC/Lazarus
It chokes on the curly braces.... *sigh*
Workaround
program Project1;
{$mode objfpc}{$H+}
Uses Sysutils, Regexpr;
Const
s1:String='554 "554 5.5.1 Error: no valid recipients"';
s2:String='554 554 5.5.1 Error: no valid recipients'; //No Double quotes
e:Array[Boolean] Of String=('(\d+?)\s+(.+)','(\d+?)\s+"(.+)"');
Var
CodiceErr:Integer;
Errore:String;
RegEx:TRegExpr;
b:Boolean;
c:Boolean;
begin
RegEx:=TRegExpr.Create;
RegEx.ModifierG:=True;
c:=Pos('"',s1)>0;
RegEx.Expression:=e[c];
RegEx.InputString:=s1;
b:=RegEx.Exec;
If b and (RegEx.SubExprMatchCount=2) Then
Begin
CodiceErr:=RegEx.Match[1].ToInteger;
Errore:=RegEx.Match[2];
writeln('Source has doublequotes: ',CodiceErr);
Writeln('Source has doublequotes: ',Errore);
end;
c:=Pos('"',s2)>0;
RegEx.Expression:=e[c];
RegEx.InputString:=s2;
b:=RegEx.Exec;
If b and (RegEx.SubExprMatchCount=2) Then
Begin
CodiceErr:=RegEx.Match[1].ToInteger;
Errore:=RegEx.Match[2];
writeln('Source has no doublequotes: ',CodiceErr);
Writeln('Source has no doublequotes: ',Errore);
end;
RegEx.Free;
Readln;
end.
Note: In this version i'm removing the doublequotes from the result