m-ender / retina

A regex-based programming language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Positional "captures" and "backreferences"

m-ender opened this issue · comments

Probably a bit ambitious but this should be possible to implement this via string-preprocessing of a regex. The idea is that you have some escape sequence which remembers the position of the "cursor" in the current line, and another which asserts that this position is the same as the last one remembered. This would be incredibly useful for grid-based tasks.

One way to implement this would be this for the capture (provided s mode is deactivated):

(?<=(?<x>.)*)

And this for the backreference:

(?!(?<!^(?(x)(?!))(?<x>.)*))

The point of the double negative lookaround is that this doesn't affect the x capture stack, even if the pattern matches. Of course, one would have to ensure that x is unique.