Home > Backend Development > PHP Tutorial > How to cut out continuous pictures?

How to cut out continuous pictures?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-06 13:51:56
Original
1048 people have browsed it

For example, there is this piece of code

<code>123
<img src="1.jpg" /><img src="2.jpg" />
321321
<img src="3.jpg" /><img src="4.jpg" />

</code>
Copy after login
Copy after login

How to match and intercept

and

That is to say, I want to intercept the text with consecutive pictures in a string. If there are other characters separating the pictures, they will not be intercepted. .

Any ideas?
Can I use regular expressions?

Reply content:

For example, there is this piece of code

<code>123
<img src="1.jpg" /><img src="2.jpg" />
321321
<img src="3.jpg" /><img src="4.jpg" />

</code>
Copy after login
Copy after login

How to match and intercept

and

That is to say, I want to intercept the text with consecutive pictures in a string. If there are other characters separating the pictures, they will not be intercepted. .

Any ideas?
Can I use regular expressions?

function fn(u) {
    console.log(u);
}

var str = '123\
<img src="1.jpg" /><img src="2.jpg" />\
321321\
<img src="3.jpg" /><img src="4.jpg" />';

str.replace(/<img src="(\d+)\.jpg" \/><img src="(\d+)\.jpg" \/>/g, function(u, number1, number2) {
    if (+number1 + 1 === +number2) {
        fn(u);
    }
});
Copy after login

Output:


< img src="4.jpg" />

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template