const regex = /((?s)(\[)(\d)(\])([ ])(?=.*:LOOKUP\3=(\w+))|(\[(\d+)\])[ ])((?<artist1>Frank Sinatra)?(\s-\s)(?<title1>.*)(?<ext1>\..*)|(?<title2>.*)(\s-\s)(?<artist2>Frank Sinatra)(?<ext2>\..*)|(?<title3>.*)(?<ext3>\..*))|(?<dict>RegExDictionary:.*)$/gmi;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('((?s)(\\[)(\\d)(\\])([ ])(?=.*:LOOKUP\\3=(\\w+))|(\\[(\\d+)\\])[ ])((?<artist1>Frank Sinatra)?(\\s-\\s)(?<title1>.*)(?<ext1>\\..*)|(?<title2>.*)(\\s-\\s)(?<artist2>Frank Sinatra)(?<ext2>\\..*)|(?<title3>.*)(?<ext3>\\..*))|(?<dict>RegExDictionary:.*)$', 'gmi')
const str = `[8] Frank Sinatra - One For My Friend.flac
[51] Come Fly With Me - Frank Sinatra.dsf
[2] Frank Sinatra - Love Me Tender.flac
[17] New York, New York.mp3
[45] Singing In The Rain - Frank Sinatra.flac
RegExDictionary:LOOKUP0=00:LOOKUP1=01:LOOKUP2=02:LOOKUP3=03:LOOKUP4=04:LOOKUP5=05:LOOKUP6=06:LOOKUP7=07:LOOKUP8=08:LOOKUP9=09`;
const subst = `$6$8${title1}${title2}${title3}${ext1}${ext2}${ext3}`;
// 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