andgineer / TRegExpr

Regular expressions (regex), pascal.
https://regex.sorokin.engineer/en/latest/
MIT License
174 stars 63 forks source link

Inconsistent substitute $123 #327

Closed User4martin closed 1 year ago

User4martin commented 1 year ago

The below code basically means, that NumberFound will be true for any $1 to $89 But not for $90 and up.

That seems are strange choice.

  RegexMaxGroups = 90;
    GrpIndexes: array [0 .. RegexMaxGroups - 1] of integer; // map global group index to _capturing_ group index
  procedure FindSubstGroupIndex(var p: PRegExprChar; var Idx: integer; var NumberFound: boolean);
  begin
    Idx := ParseVarName(p);
    NumberFound := (Idx >= 0) and (Idx <= High(GrpIndexes));

The test asserts, that a number not present is ignored. But that works only up to 89. And then behaviour changes.

    // 70
    (
    expression: '(b)';
    inputText: 'abc';
    substitutionText: '$1$2$9';
    expectedResult: 'abc';
    matchStart: 1
    ),

Changing that test to $1$2$90 leads to a result of ab$c

IMHO, any $123 ... that does not have a group should be "".

User4martin commented 1 year ago

@Alexey-T

Alexey-T commented 1 year ago

IMHO, any $123 ... that does not have a group should be "".

Good catch. Agree with that.

User4martin commented 1 year ago

Is included in https://github.com/User4martin/TRegExpr/commits/group-idx