function replaceUrlPatterns(url, sedLikeReplacementPatterns) {
  let replaced = url;

  for (const pattern of sedLikeReplacementPatterns) {
    const match = pattern.match(/^s(.)(.*)\1(.*)\1([gim]*)$/);
    if (!match) throw new Error(`Invalid URL replacement pattern "${pattern}"`);
    const [needle, replacement, flags] = match.slice(2);
    const regex = new RegExp(needle, flags);
    replaced = replaced.replace(regex, replacement);
  }

  return replaced;
}
@param {string} url
@param {string[]} sedLikeReplacementPatterns