js regular filtering and adding image prefixes in rich text

1. Filter the image prefix without '/' and turn it into a relative path. The following two regular rules are available. Personal test


// 示例,过滤图片前缀且不带'/',变成相对路径

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="${你的域名}`)

Reference materials:Use regular expressions to add domain names to rich text image tags for display, delete domain names and submit_qq_43675010's blog-CSDN blog

Guess you like

Origin blog.csdn.net/u014678583/article/details/125594103