replaceLater.forEach( function ( widget, i ) { config = config.replace( // Match any number of spaces (for indentation) followed by our placeholder new RegExp( '([ ]+)"' + replaceKeyword + i + '"' ), function ( all, indent ) { var code = getCode( widget ); // Re-add the indent at the beginning, and after every newline return indent + code.replace( /\n/g, '\n' + indent ); } ); } );