Closed Uefi1 closed 1 year ago
2. give the compilable example for FreePascal
function pars(n:integer;RegString : AnsiString; thmlcode: AnsiString):TStringList; var RegExp: TRegExpr; begin RegExp := TRegExpr.Create; RegExp.ModifierS := true; RegExp.ModifierM:=true; RegExp.InputString := thmlcode; RegExp.Expression := RegString; try try if RegExp.Exec then repeat textmp.Add(RegExp.Match[n]); until RegExp.ExecNext=false; except end; finally RegExp.Free; end; result:=textmp; end;
procedure TForm1.Button2Click(Sender: TObject); begin Base:=Tstringlist.Create; Base.Clear; if opendialog1.Execute then Base.LoadFromFile(Opendialog1.FileName); end;
procedure TForm1.Button1Click(Sender: TObject); begin textmp:=TStringList.Create; memo1.lines.AddStrings(pars(1,'2:\s(.+)\s3:\s(.+)',Base.text)); freeandnil(textmp); end;
Please attach the zip file with needed files- .lpr .pas .lfm .lpi files.
Please attach the zip file https://dropmefiles.com/ihehD
I made Linux app now
how to see error here??
how to see error here??
No errors, parses the word incorrectly create .txt from words and openned it:
1: batman 2: lenin 3: money 4: this
lenin? Are you trolling here? maybe hitler too?
Words are not important, they are taken in guesswork
I tested on my file. I see it is OK .
if ModifierS=True, group[2] takes all text from "3: " until end of file. if ModifierS=False, group[2] takes only one line after "3:"
Lazarus/ Linux
I tested on my file. I see it is OK .
Sorry try with this regex: https://regex101.com/r/xSf83d/1
And This is Words in text file:
1: batman 2: lenin 3: money 4: this
1: superman
2: rabbit
3: deep
4: thanks
@Uefi1 Your Pascal code sets the modifiers S, G and M (S and G are on by default). Your regex101 code sets the modifiers G, M and I. And not S. Add S to it, otherwise you're comparing apples with oranges.
@andgineer Seems user mis-tests the S regex modifier. seems all is OK in the code. let's close?
Hello, RegExp.ModifierS grabs extra lines
var RegExp: TRegExpr; begin RegExp := TRegExpr.Create; RegExp.ModifierS := true; RegExp.ModifierM:=true;
https://regex101.com/r/hDp6q8/1
Delphi: lenin 3: money 4: this