Help with regex lazarus / 61-Beginners ---------------------------------------------------------------------- howisitpossible · 2021-01-13 19:18 I'am trying to launch my code but it crashes on line Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if (reg.Exec(txt)) then. Textfile is html- page:https://en.wikipedia.org/wiki/D_(programming_language) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; uses  RegExpr;var  txt, buf, filename:string;  fileHtml:Textfile;  reg:TRegExpr;begin  write('Name of html-file: ');  read(filename);   AssignFile(fileHtml, filename);  Reset(fileHtml);   txt:='';  while not Eof(fileHtml) do  begin    Readln(fileHtml, buf);    txt:=txt+buf;  end;   reg:=TRegExpr.Create('()(?![\s\S]*\1)');  if (reg.Exec(txt)) then  repeat    writeln(reg.Match[0]);  until not reg.ExecNext; end. ---------------------------------------------------------------------- BlueIcaro · 2021-01-13 19:59 Hi, I'm not a expert in RegExpresion. But If I put the mouse over the line 23, lazarus gives a warning about a error in expression. See attach image ---------------------------------------------------------------------- AlexTP · 2021-01-13 20:12 Did you see the error in terminal? Look Quote[user:~]$ ./regtst Name of html-file: tst.html An unhandled exception occurred at $0000000000430B5A: ERegExpr: TRegExpr compile: unrecognized modifier (pos 22) It means that RegExpr gives error for regex. ---------------------------------------------------------------------- howisitpossible · 2021-01-13 20:14 I can't understand what is wrong ---------------------------------------------------------------------- howisitpossible · 2021-01-13 20:16 Quote from: BlueIcaro on January 13, 2021, 08:59:19 pmHi, I'm not a expert in RegExpresion. But If I put the mouse over the line 23, lazarus gives a warning about a error in expression. See attach image Hmm, i have no warnings ---------------------------------------------------------------------- BlueIcaro · 2021-01-13 20:17 Hi, see the picture attached. Debuger raises a exception: unrecognized modifier(pos2) I'm testing in Ubuntu x64 20.04 with Lazarus 2.10 with this code Code: [Select]program project1; {$mode objfpc}{$H+} uses {$IFDEF UNIX} {$IFDEF UseCThreads}   cthreads, {$ENDIF} {$ENDIF}   Classes { you can add units after this },   RegExpr; var   txt, buf, filename: string;   fileHtml: Textfile;   reg: TRegExpr; begin   //write('Name of html-file: ');   //read(filename);   //AssignFile(fileHtml, filename);   //Reset(fileHtml);   //txt:='';   //while not Eof(fileHtml) do   //begin   //  Readln(fileHtml, buf);   //  txt:=txt+buf;   //end;   txt := '       Esta es mi primera pagina    

Esto es un encabezado

   

Y esto es un parrafo, donde podemos escribir todo el rollo que se nos ocurra.';   reg := TRegExpr.Create('()(?![\s\S]*\1)');   if (reg.Exec(txt)) then     repeat       writeln(reg.Match[0]);     until not reg.ExecNext; end.  /BlueIcaro ---------------------------------------------------------------------- AlexTP · 2021-01-13 20:17 Regex uses ASSERTION which is supported only in last TRegExpr from https://github.com/andgineer/TRegExpr ---------------------------------------------------------------------- howisitpossible · 2021-01-13 20:19 Can you help me to correct this regex? ---------------------------------------------------------------------- BlueIcaro · 2021-01-13 20:21 Quote from: howisitpossible on January 13, 2021, 09:19:02 pmCan you help me to correct this regex? Here is some info https://regex.sorokin.engineer/en/latest/tregexpr.html /BlueIcaro ---------------------------------------------------------------------- paweld · 2021-01-13 20:28 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; uses  Classes, RegExpr; var  filename:string;  sl: TStringList;  reg:TRegExpr; begin  write('Name of html-file: ');  read(filename);  sl := TStringList.Create;  sl.LoadFromFile(filename);  reg := TRegExpr.Create('');  if (reg.Exec(sl.Text)) then  repeat    writeln(reg.Match[0]);  until not reg.ExecNext;  sl.Free;end. ---------------------------------------------------------------------- howisitpossible · 2021-01-13 20:35 Quote from: paweld on January 13, 2021, 09:28:52 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; uses  Classes, RegExpr; var  filename:string;  sl: TStringList;  reg:TRegExpr; begin  write('Name of html-file: ');  read(filename);  sl := TStringList.Create;  sl.LoadFromFile(filename);  reg := TRegExpr.Create('');  if (reg.Exec(sl.Text)) then  repeat    writeln(reg.Match[0]);  until not reg.ExecNext;  sl.Free;end. does it find without repetitions? ---------------------------------------------------------------------- sstvmaster · 2021-01-13 21:37 You can use this RegEx: ]+> with tags This RegEx needs too much steps: ()(?![\s\S]*\1) With reg.Match[0] it is with tags With reg.Match[1] it is the image url only Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; uses  Classes, RegExpr, SysUtils; var  i: Integer;  sl: TStringList;  reg: TRegExpr;  sum: String = 'Found %d matches in ~%dms.';  cstart, cstop: Int64;begin  cstart := GetTickCount64;  i := 0;  sl := TStringlist.Create;  sl.LoadFromFile('wikipedia.txt');  reg := TRegExpr.Create;   reg.Expression := ']+>'; if reg.Exec(sl.Text) then  repeat    WriteLn(reg.Match[0]); // with tags    //WriteLn(reg.Match[1]); // image url only    Inc(i);  until not reg.ExecNext();  cstop := GetTickCount64-cstart;   WriteLn;  WriteLn(Format(sum, [i, cstop]));   ReadLn;end. ---------------------------------------------------------------------- sstvmaster · 2021-01-13 22:30 @AlexTP this RegEx do not work: ]+src=(?:"|'')\K(.[^">]+?)(?="|'') I use your lastest regex!!! ---------------------------------------------------------------------- AlexTP · 2021-01-13 23:58 Just read the docs. At Sorokin's site. \K is NOT supported. The regex error tells that ---------------------------------------------------------------------- trev · 2021-01-14 00:52 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i reg:=TRegExpr.Create('(]+)(src=["\''])([^"\'']+)');   if (reg.Exec(txt)) then     repeat        writeln('0: ',reg.Match[0]);      writeln('1: ',reg.Match[1]);        writeln('2: ',reg.Match[2]);      writeln('3: ',reg.Match[3]);     until not reg.ExecNext; produces: Quote0: (the ^ in [^>]+ means do not match > and the + means match one or more characters, so match everything up but not including the closing >) * the second match (match[1]) is on the expression