javascript - js writes a regular expression to extract data from text
给我你的怀抱
给我你的怀抱 2017-07-05 10:43:25
0
2
821

I have a text like this:

<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>

Use js to write regular rules to extract part of the src value of all img tags in , and then use /@/# to extract the multiple values ​​ ##Splicing into a new string

20170701/6363450829304727881702482.jpg/@/20170701/6363450829304727881702483.jpg
给我你的怀抱
给我你的怀抱

reply all(2)
仅有的幸福
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);

Effect:

给我你的怀抱
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('/@/'))

Online experience

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template