$re = '/(?\'group1\'[\d])/m';
$str = '101011010
110101101
111010110
111101011
011110101
101111010
110111101
011011110
001101111
100110111
110011011
111001101
111100110
011110011
001111001
100111100
010011110
001001111
100100111
010010011
001001001
000100100
000010010
000001001
000000100
000000010
100000001';
$subst = "$1 & ";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php