I've a string describing a matrix of n x m elements like this one:
§inputmap = "
~~~~~~~~~~~~~~~~~~~~B~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~BBB........BBB~~~~~~~~~~~~~
~~~~~~~~~~BB...............FBB~~~~~~~~~~
~~~~~~~~BB....................BB~~~~~~~~
~~~~~~BB.....F..................BB~~~~~~
~~~~~BB.....................F.....B~~~~~
~~~~B..............................B~~~~
~~~B........F.......................B~~~
~~BB.........F......................BB~~
~~B................F.................BB~
~BF....F....F........................FB~
~B.....................................B
B.....................................FB
B........F......F......................B
B...........................F..........B
B......................................B
B......................................B
B.......F.......................F......B
B......FFF.............................B
B.......F.............................FB
~B..................F.................FB
~BF...........................F.......B~
~~B...F...........F..........FFFFF.F.BB~
~~BB..................F..F....F.....BB~~
~~~B.......................FF.FF....B~~~
~~~~B..............................B~~~~
~~~~~BB...........................B~~~~~
~~~~~~BB........................BB~~~~~~
~~~~~~~~BB..........F..........B~~~~~~~~
~~~~~~~~~~BB................BB~~~~~~~~~~
~~~~~~~~~~~~~BBB.......F.BBB~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~BBBBBB~~~~~~~~~~~~~~~~~
";
$inputmap = trim($inputmap);
I need to build a regular expression (or something else) to search the string:
$search = "
*F*
FFF
*F*
";
$search = trim($search);
on the whole grid. On other hands I need to find a pattern of 5 distinct letter "F" (3 vertically and 3 horizzontally) getting back the rows/columns position of the pattern(s) found on the map.
Considering that the input matrix can be different (5x5 or 10x10 or 20x25 or ...), is there a way to solve my problem with php and regular expressions?