const regex = /(\d+\[\d-\d])\n/gs;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(\\d+\\[\\d-\\d])\\n', 'gs')
const str = `922337203685477580[8-9]
9223372036854775[9-9]
922337203685477[6-9]
92233720368547[8-9]
9223372036854[8-9]
922337203685[5-9]
92233720368[6-9]
9223372036[9-9]
922337203[7-9]
92233720[4-9]
922337[3-9]
92233[8-9]
9223[4-9]
922[4-9]
92[3-9]
9[3-9]`;
const subst = `\1|`;
// 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