const regex = /(?:^Time_in_seconds\[\d+\]Time_in_seconds$(\R?))+/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:^Time_in_seconds\\[\\d+\\]Time_in_seconds$(\\R?))+', 'gm')
const str = `Time_in_seconds[1]Time_in_seconds
Time_in_seconds[123]Time_in_seconds
Time_in_seconds[*]Time_in_seconds
Time_in_seconds[1]Time_in_seconds
Time_in_seconds[2]Time_in_seconds
Time_in_seconds[3]Time_in_seconds`;
const subst = `My new line$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