andgineer / TRegExpr

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

Feature \G please #297

Closed User4martin closed 1 year ago

User4martin commented 1 year ago

Could \G be implemented please?

https://www.tutorialspoint.com/regular-expression-g-metacharacter-in-java

Also ATextStartOffset in FRegEx.Exec(ATextStartOffset)

User4martin commented 1 year ago

@Alexey-T is this something you could help, please?

Alexey-T commented 1 year ago

Maybe ... but I did not understand the text about \G. i didn't get the info on your link. and on this link- https://stackoverflow.com/questions/14897949/what-is-the-use-of-g-anchor-in-regex

Alexey-T commented 1 year ago

first answer here https://stackoverflow.com/questions/14365969/how-the-anchor-z-and-g-works-in-ruby/14366062#14366062 is good, but I still don't understand this idea.

Alexey-T commented 1 year ago

OK I got the idea. after some time. is it possible in engine - will think...

Alexey-T commented 1 year ago

Martin, it is the not hard change. i hope you can make the PR. its easy to remember the end of the match after successfull Exec* call, in the new variable, and it's easy to add the \G which handler must only compare the current-pos with that variable

let's add opcode OP_PREV_END.

I forgot the code, but here is example for COMPILING \A and \z

          'A':
            ret := EmitNode(OP_BOL);
          'z':
            ret := EmitNode(OP_EOL);

handler of EXEC* will be near this code:

      OP_BOL: //for \A
        begin
          if regInput <> fInputStart then
            Exit;
        end;

      OP_EOL: //for \z
        begin
          // \z matches at the very end
          if regInput < fInputEnd then
            Exit;
        end;
Alexey-T commented 1 year ago

@User4martin Let's close?