BeRo1985 / flre

FLRE - Fast Light Regular Expressions - A fast light regular expression library
GNU Lesser General Public License v2.1
94 stars 23 forks source link

minimum length of subsequent + #69

Open benibela opened 3 years ago

benibela commented 3 years ago

Subsequent + imply a minimal length of the string.

These match, but should not:

 writeln(TFLRE.Create('^(?:\d+\d+\d+)$', []).Find('12'));
 writeln(TFLRE.Create('^(?:\d+\d+\p{Nd}\d+)$', []).Find('123'));
benibela commented 1 year ago

This is still broken

See also:

program Project1;
uses FLRE;
var
  f: TFLRE;
begin
  f := TFLRE.Create('^(?:\d+\d+\d+\d+)$', []);
writeln(  f.DumpRegularExpression );
  writeln(f.Test('1'));
  writeln(f.Test('12'));
  writeln(f.Test('123'));
  writeln(f.Test('1234'));
  writeln(f.Test('12345'));
end.

My PR #77 had fixed it

Perhaps it should be like this now:

function ConcatEqualPlus(const NodeLeftMightBecomeCat,PlusNodeRight:PFLRENode):PFLRENode;
 begin
  if (NodeLeftMightBecomeCat^.NodeType=ntPLUS)
    // assigned(NodeLeftMightBecomeCat^.Right) and
//     (PlusNodeRight^.NodeType=ntPLUS)
     then begin
   NodeLeftMightBecomeCat^.NodeType:=ntCAT;
   NodeLeftMightBecomeCat^.Right:=PlusNodeRight;
   result:=NodeLeftMightBecomeCat;
  end else begin
   result:=PlusNodeRight;
  end;
 end;