![]() |
|
Syntactic Confectionery Delight | |
PerlMonks |
RE: vertical regex in a matrix?by BooK (Curate) |
on Sep 11, 2000 at 18:36 UTC ( [id://31886]=note: print w/replies, xml ) | Need Help?? |
When you want do things such as working with multiline strings that represent a board (or a matrix or whatever), the best way is to unfold the string. Either by removing the \n, and printing the line
with something like: Here I use the latter solution. You can use two regex,
if your input is indeed a matrix (i.e. all lines are of
the same length). First you can work the 'Y' columns, and
then the 'x' line:
There are more than one way to do this. What is it that you specifically want to do? Replace all vertical 4's by Y's or what? Tips: /m let ^ and $ match the beginning and the ending of a line (on a multiline string). \A and \Z match the beginnning and ending of the string. I also used the fact that . doesn't match a newline, so the second regex cannot match further than the first line. I am not really sure it's smarter than transposition, though...
In Section
Seekers of Perl Wisdom
|
|