Let's say I've have the code like this:\[code\]<img src="http://stackoverflow.com/questions/14083989/001"><img src="http://stackoverflow.com/questions/14083989/002"><p>Some content here.</p><img src="http://stackoverflow.com/questions/14083989/003">\[/code\]What I want to do now is to match the first two images (001 and 002) and store that part of the code in variable. I don't want to do anything with third image.Id used something like \[code\]preg_match_all('/<img .*>/', $result);\[/code\] but it obviously matched all the images. Not just those which appear on the top of the code. How to modify that regular expression to select just images that are on top of the code.What I want to do is to now. I've have \[code\]<h2>\[/code\] tag with title in one variable and the code above in the second. I want to move the first X images before the \[code\]<h2>\[/code\] tag OR insert that \[code\]<h2>\[/code\] tag after first X images. All that in back-end PHP. Would be fun to make it with CSS, but flexbox is not yet here.