const regex = new RegExp('(^reflectance_\\d_)(\\S*)$', 'gm')
const str = `reflectance_7_myd21a1_emissivity_29
reflectance_7_myd21a1_emissivity_29_savitzkygolay
reflectance_7_myd21a1_emissivity_31
reflectance_7_myd21a1_emissivity_31_savitzkygolay
reflectance_3_myd21a1_emissivity_32
reflectance_2_myd21a1_emissivity_32_savitzkygolay
reflectance_1_mcd43a3_albedo_bsa_band1
reflectance_3_mcd43a3_albedo_bsa_band2
reflectance_7_mcd43a3_albedo_bsa_nir
reflectance_7_mcd43a3_albedo_bsa_shortwave
reflectance_7_mcd43a3_albedo_bsa_vis
reflectance_7_mcd43a3_albedo_wsa_band1
reflectance_7_mcd43a3_albedo_wsa_band2
reflectance_7_mcd43a3_albedo_wsa_nir
reflectance_7_mcd43a3_albedo_wsa_shortwave
reflectance_7_mcd43a3_albedo_wsa_vis`;
const subst = `($1)vs_$2`;
// 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