我有这样的一个文本:
<p>sdsadsad</p><p><img src="/Edite/net/upload/image/20170701/6363450829304727881702482.jpg" title="ewe.jpg" alt="ewe.jpg"/><img src="/Edite/net/upload/image/20170701/6363450829304727881702483.jpg" title="ewe.jpg" alt="ewe.jpg"/></p>
用js 写正则提取里面所有的img标签的src值的一部分,然后将提取到的多个值用/@/
拼接成一个新的字符串
20170701/6363450829304727881702482.jpg/@/20170701/6363450829304727881702483.jpg
仅有的幸福2017-07-05 10:45:25
var html = '<p>sdsadsad</p><p><img src="/Edite/net/upload/image/20170701/6363450829304727881702482.jpg" title="ewe.jpg" alt="ewe.jpg"/><img src="/Edite/net/upload/image/20170701/6363450829304727881702483.jpg" title="ewe.jpg" alt="ewe.jpg"/></p>';
var txt = html
.match(/src="([^"]*?)"/g)
.map(m => m.replace(/^src="\/Edite\/net\/upload\/image\/([^"]*)"$/, ''))
.join('/@/');
console.log(txt);
效果:
给我你的怀抱2017-07-05 10:45:25
const html = `<p>sdsadsad</p><p><img src="/Edite/net/upload/image/20170701/6363450829304727881702482.jpg" title="ewe.jpg" alt="ewe.jpg"/><img src="/Edite/net/upload/image/20170701/6363450829304727881702483.jpg" title="ewe.jpg" alt="ewe.jpg"/></p>`;
console.log(html.match(/src="([^"]*?)"/g).map(m => m.replace('src="/Edite/net/upload/image/', '').replace(/"/g, '')).join('/@/'))
在线体验