do you have to store all that in a string? if the answer is no i would recommend a different approach.
first: use a two dimensional array (array of arrays).
that would loke like this:
$coords = array($coords = array(
array(1,1,0,1,0,1,1,0,1,1,0,1,0),
array(0,0,0,1,0,1,1,1,1,1,0,1,0),
...
);
if you want to have an "empty slot" use a "null" instead of 0 or 1.
$coords = array($coords = array(
array(1,1,0,1,0,1,1,0,1,1,null,1,0),
array(0,0,0,1,0,1,1,1,1,1,0,1,0),
...
);
the next requirement of having multiple lines of 1111 in that field is easy:
$coords = array($coords = array(
array(1,1,0,1,0,1,1,0,1,1,array(
array(1,1,1),
array(1,1,1)),1,0),
array(0,0,0,1,0,1,1,1,1,1,0,1,0),
...
);
if you need a string representation, use the serialize function of php after you have manipulated the data in the array. if you need a special string representation, write your own serialize-function. it's much easier AND faster to work with arrays, than to work with strings and regexp.