const regex = /(?m)^[^\S\r\n]*(\S+)[ \t]+(\S+)[ \t]+(\S+(?:[^\S\r\n]*\S+)*)/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?m)^[^\\S\\r\\n]*(\\S+)[ \\t]+(\\S+)[ \\t]+(\\S+(?:[^\\S\\r\\n]*\\S+)*)', 'g')
const str = ` FOO 100 BOR
PAL 350 PIL
KIL 090 KUP
FAS 130 FOO's BAR
FAO 120 Pizza's joy poy`;
const subst = `array($2, "$1", "$3"),`;
// 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