I'm hoping someone has a clever way to do this...
Okay, I have an array of arrays (which can just as easily be an array of strings, just don't split the strings into individual characters) and want to perform substitutions vertically. i.e., given this matrix:
xxxYYxxxYYxxx
YY YY
4Y 4X
4Y 4Y
YY YY
I'd like to do two things, first of all, change all Y's horizontally between x's into x's themselves, and change all 4's vertically between Y's into Y's themselves. This is the result:
xxxxxxxxxxxxx
YY YY
YY YX
YY YY
YY YY
Now, the horizontal match to turn the Y's into x's is easy, just join on the line and do the regex as normal. But what's a nice, clever way to do the vertical match to turn the 4's into Y's? (don't worry about precedence compared to the horizontal match)
I know I can always transpose the matrix, do the now horizontal substitution, and then transpose it back, but that seems like an awful lot of effort. Anyone know a smarter way to do it?