$re = '/^\h*
(?<linetype>[0123456])\h+
(?<color> (?&Number) )\h+
(?<xrot> (?&Number) )\h+ (?<yrot> (?&Number) )\h+ (?<zrot> (?&Number) )\h+
(?<xpos> (?&Number) )\h+ (?<ypos> (?&Number) )\h+ (?<zpos> (?&Number) )\h+
(?<xcam> (?&Number) )\h+ (?<ycam> (?&Number) )\h+ (?<zcam> (?&Number) )\h+
(?<xsca> (?&Number) )\h+ (?<ysca> (?&Number) )\h+ (?<zsca> (?&Number) )\h+
(?<filename>\S+[.]\S+)
$
(?(DEFINE)
(?<Number> [-]? \d+ (?> [.]\d* )? (?> [Ee] [+-]? \d+ )? )
)/mx';
$str = '1 0 0 0 0 1 0 0 0 1 0 0 0 1 3024.dat
#linetype color XROT YROY ZROT XPOS YPOS ZPOS XCAM YCAM ZCAM XSCA YSCA ZSCA FILE';
$subst = "${linetype} ${color} ($xrot,$yrot,$zrot) {$xpos,$ypos,$zpos} <$xcam,$ycam,$zcam> [$xsca,$ysca,$zsca] \"$filename\"";
$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