0

Having this text:

<div align="center"><img src="media/k2/local/594b89d436f4b.jpeg" border="0" alt="" /><br /><br /><img src="media/k2/local/594b89d59fe0b.jpeg" border="0" alt="" /><br /><br /><img src="media/k2/local/594b89d68659f.jpeg" border="0" alt="" /><br /><br /><img src="media/k2/local/594b89d7289b6.jpeg" border="0" alt="" /><br /><br /><img src="media/k2/local/594b89d7cc2db.jpeg" border="0" alt="" /><br /><br /><img src="media/k2/local/594b89d8e3c3d.jpeg" border="0" alt="" /><br /><br /><img src="media/k2/local/594b89d9c732d.jpeg" border="0" alt="" /></div>

<img src="media/k2/local/594b89d436f4b.jpeg" border="0" alt="" />

<img src="media/k2/local/2.jpeg" border="0" alt="" />

I use the following regex to exactract the image urls:
<img(.+)src=[\'"](.+?)[\'"](.*?)\>

The thing is that this works correctly when the images are separated by line breaks.

From the first line of the example above, it takes only the last url when I want to get all of them. The second and third line, I get the URL correctly.

Demo: https://regex101.com/r/uXWFnW/2

How can I modify my regex in order to get all the urls that are in the same line? (the url must fit on group #2)

Thanks in advance.

1
  • Which flavor do you use? Commented Jul 3, 2017 at 9:46

1 Answer 1

1

Try the following regex:

<img(.+?)src=[\'"](.+?)[\'"](.*?)\>

I added the ? after the first .+ to make this search non-greedy.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.