const regex = /(?<!^)[ \t]*\r?\n(?=\$)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?<!^)[ \\t]*\\r?\\n(?=\\$)', 'gm')
const str = `\$index 57320
\$title The vertex-cover polynomial of a graph
\$time 1988
\$abstract In this paper we define the vertex-cover...
\$index 57321
\$title Locating stations on rapid transit lines
\$time 1978
\$index 57322
\$title Fast heuristics for large scale covering-location problems
\$time 1998
\$abstract We propose fast heuristics for large scale...
\$index 57323
\$title Efficient vector processing on dataflow supercomputer SIGMA-1
\$time 2001
\$abstract Efficiency in vector handling is the key to obtaining high... `;
const subst = `,`;
// 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