$re = '/^\s*[#%\/]*\s*(.*)[\n\r]/m';
$str = '% x=(1:20)\';
% y=randn(20,1);
% [bhat p wh se ci t_stat]=robust_fit(x,y,1);
% figure;plot(x,y,\'.\'); hold on; plot(x,bhat(1)+bhat(2).*x,\'r\')
% plot(x,[ones(length(x),1) x]*(([ones(length(x),1) x]\'*[ones(length(x),1) x])\\([ones(length(x),1) x]\'*y)),\'k\')
% legend(\'Data\',\'Robust\',\'Non-robust\')
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
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