const regex = /(^https?:\/\/www\.dropbox\.com)(\/s\/\w+\/[\wа-яА-Яё]+\.\w+).*/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(^https?:\\\/\\\/www\\.dropbox\\.com)(\\\/s\\\/\\w+\\\/[\\wа-яА-Яё]+\\.\\w+).*', 'gm')
const str = `https://www.dropbox.com/s/2f15pra2dssf7zvwf7b/333.jpg?dl=0
https://www.dropbox.com/s/rhdkdf15dykctjdp004/376.jpg?dl=0
https://www.dropbox.com/s/kx70sj1gru4vsawhg9/517.jpg?dl=0`;
const subst = `https://dl.dropboxusercontent.com$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