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?
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" />