const regex = /^\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+ )? )
)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^\\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+ )? )
)', 'gm')
const 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`;
const subst = `${linetype} ${color} ($xrot,$yrot,$zrot) {$xpos,$ypos,$zpos} <$xcam,$ycam,$zcam> [$xsca,$ysca,$zsca] "$filename"`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', 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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions