const regex = /(<?)(https?.*?)(>?)(\)\*)(.*?)(\*)(.*)/gmiu;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(<?)(https?.*?)(>?)(\\)\\*)(.*?)(\\*)(.*)', 'gmiu')
const str = ` link="https://en.wikipedia.org/wiki/File:Black_Widow_(2021_film)*poster.jpg#/media/File:Black_Widow*(2021_film)_poster.jpg"
link="<https://en.wikipedia.org/wiki/File:Writer%27s_Odyssey_(2021_film>)*poster.jpeg#/media/File:Writer's_Odyssey*(2021_film)_poster.jpeg"
src="https://en.wikipedia.org/wiki/File:Black_Widow_(2021_film)*poster.jpg#/media/File:Black_Widow*(2021_film)_poster.jpg"
src="<https://en.wikipedia.org/wiki/File:Writer%27s_Odyssey_(2021_film>)*poster.jpeg#/media/File:Writer's_Odyssey*(2021_film)_poster.jpeg"
`;
const subst = `$2)_$5_$7`;
// 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