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

<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>
Copy after login

Output:


< img src="4.jpg" />

Related labels:
source:php.cn
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
Latest Issues
html5 validation for symfony 2.1
From 1970-01-01 08:00:00
0
0
0
The difference between HTML and HTML5
From 1970-01-01 08:00:00
0
0
0
html5 show hide
From 1970-01-01 08:00:00
0
0
0
Can PDF files run HTML5 and Javascript?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template