我有這樣的一個文字:
<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('/@/'))
線上體驗