JavaScript正则加上/去掉cdn域名前缀,文本支持
<script>
let $domain="https://static-project.example.com";
let html = '[{"content":"/project-name/prod/supplier/1/41/2024-09/28/1123.jpg","cat":1},{"content":"/project-name/prod/supplier/1/41/2024-09/28/1123","cat":1}]';
console.log('===========================原始数据=============================')
console.log(html);
let result = html.replace(/\/project-name\/(prod|dev|test)\//g, $domain + "/project-name/$1/");
console.log('===========================加域名数据=============================')
console.log(result);
let result2 = result.replace(new RegExp($domain,'g'),"");
console.log('===========================去域名数据=============================')
console.log(result2)
</script>
执行结果参考:
https://www.leftso.com/article/2410181516064412.html