当前位置:网站首页>JS regular filtering and adding image prefixes in rich text

JS regular filtering and adding image prefixes in rich text

2022-07-06 02:49:00 Residual temperature without trace

1、 Filter image prefixes without '/', Become a relative path , The following two regularities are ok , Personal test


//  Example , Filter image prefixes without '/', Become a relative path 

console.log('valueHtml', valueHtml.replace(/https?:\/\/[^\/]*(\/)*/g, ''));

console.log('valueHtml', valueHtml.replace(/\bhttps?:\/\/(.*?)\/+/ig, ''));

2、 Add picture prefix  


valueHtml= result.detail.content.replace(/<img [^>]*src=['"]/g, `<img src="${ Your domain name }`)

Reference material : Use regular expressions to add domain names to rich text image labels for display 、 Delete domain name submission _qq_43675010 The blog of -CSDN Blog

原网站

版权声明
本文为[Residual temperature without trace]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060246229085.html