Link to home
Create AccountLog in
Avatar of rlb1
rlb1

asked on

How do I structure this Regex?

Experts,

I am new to Regex.  

What Regex would I use to get the result of only:
40294a.jpg
40294b.jpg
40294c.jpg
40294d.jpg

I am attempting to get all 4 results in an array, however, I am only able to get one result.   Please note: The stock number of "40294" will change on each product.  

Thanks for your help!!



// My Code gets only one reult of 40294.jpg.

preg_match('%<img src="/product-images/40294/50/(.*?).jpg" style="border:solid 1px #D6D6D6; border-collapse:separate;" />%s',$data,$matches3);

$photos1=$matches3[1];
$photos2=$matches3[2];
$photos3=$matches3[3];
$photos4=$matches3[4];

echo $photos1."<br />";
echo $photos2."<br />";
echo $photos3."<br />";
echo $photos4."<br />";



// Source Code ***********************************

<div style="float:left; padding-left:3px;">                        
                     
					    <a href="hires-image-viewer.asp?sku=40294&image=0" 
					       target="_blank"
					       rel="nofollow"
					       onclick="return displayHiResImageViewer('40294', 0);"					       
					       style="display:inline; float:left; border-style:none;  margin-left:-1px; ">
					        <img src="/product-images/40294/50/40294a.jpg" style="border:solid 1px #D6D6D6; border-collapse:separate;" />
					    </a>
					    
					    <a href="hires-image-viewer.asp?sku=40294&image=1" 
					       target="_blank"
					       rel="nofollow"
					       onclick="return displayHiResImageViewer('40294', 1);"					       
					       style="display:inline; float:left; border-style:none;  margin-left:-1px; ">
					        <img src="/product-images/40294/50/40294b.jpg" style="border:solid 1px #D6D6D6; border-collapse:separate;" />
					    </a>
					    
					    <a href="hires-image-viewer.asp?sku=40294&image=2" 
					       target="_blank"
					       rel="nofollow"
					       onclick="return displayHiResImageViewer('40294', 2);"					       
					       style="display:inline; float:left; border-style:none;  margin-left:-1px; ">
					        <img src="/product-images/40294/50/40294c.jpg" style="border:solid 1px #D6D6D6; border-collapse:separate;" />
					    </a>
					    
					    <a href="hires-image-viewer.asp?sku=40294&image=3" 
					       target="_blank"
					       rel="nofollow"
					       onclick="return displayHiResImageViewer('40294', 3);"					       
					       style="display:inline; float:left; border-style:none;  margin-left:-1px; ">
					        <img src="/product-images/40294/50/40294d.jpg" style="border:solid 1px #D6D6D6; border-collapse:separate;" />
					    </a>
					    
				    </div>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of rlb1
rlb1

ASKER

THANK YOU!!!    One follow up question...  

Is there a way to have the "40294" in this statement /40294/50/(.*?).jpg overlooked if it needs to be included to get the exact data you want off of a webpage?  

Solution worked great!!!



Not sure what you're asking in the follow up question. Try accepting this one, and opening a new one for that.

From what I can glean from your statement, I think that /.*/ will "overlook" it.
Avatar of rlb1

ASKER

DrDamnit:
Thank you for your help!!  Please respond to the related question I will ask in a moment.  

amit_g::
Thank you for your help!!
Avatar of rlb1

ASKER

Thank You Both!!!