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

How to cut out continuous pictures?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-06 13:51:561039browse

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>

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>

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?

<code class="javascript">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);
    }
});</code>

Output:


< img src="4.jpg" />

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