http://qs1969.pair.com?node_id=493600


in reply to Multidimensional regular expressions

Were you thinking of something along the lines of Befunge, but for regexen?

Merging a Befunge-like syntax with Perl regex syntax would be amazing. Maybe some interesting alternations such as

\d{?[^>]}
to look north and east from the "current" position for a digit.

Using NFA ideas, split the "current" position, and check more than one path. For example, look for palindromes in 1D strings:

m/( # capture whole match (.)? # 0 or 1 middle char ( # capture matched pairs . # 1 char {?\2[<]} # ...left of \2 {?[eq]} # string equal {?\2[>]} # ...right of \2 )* # zero or more times ) # close capture /x;
except that it needs some way to refer to the growing match at each point.

Solving those path problems, like "you can only move to postions which are red on odd moves, and blue or green on even moves", would be easier.

This would need to capture not only the characters matching the regex, but the path as well, since it can no longer be assumed that the chars are in a straight line. Also, can characters already matched be matched again?

This fundamentally depends on what it means to have a multideminsional string. Is a 2D string an array of strings taken in order from $x[0] to $x[$#x]? Is a 3D string an AoA of strings? Or is a 2D string just a normal string with more than one newline? (Then what would a 3D string look like?)

-QM
--
Quantum Mechanics: The dreams stuff is made of