Skip to content

Implement lookbehinds #4

Description

@refi64

There are two ways to approach this:

  1. Figure out the length N of the lookbehind assertion, and check for it exactly N characters back in the string. This is what Python does. I personally find it slightly restrictive...
    2. Allow any expression. Just step back through the string one character at a time and test if the lookbehind matches AND ends right at the previous position. This is obviously very slow but much more flexible. One optimization here could be to calculate the minimum length of the match and start there. Doing the same thing with a max length may not be worth it, since stuff like (?<=a{2,5}) isn't that common.

My idea is to combine both: when the first approach can be used, then use it! When the given regex wouldn't work with it (e.g. (?<=a+)b), then use method 2. Using method 2 in practice utterly failed. Not even Perl allows that. I just went with method 1.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions