On Apr 10, 11:03 pm, jwkr...@shaw.ca ("John W. Krahn") wrote: > cityuk wrote: > > Dear All, > > Hello, > > > > > This is more of a generic question on regular expressions as my > > program is working fine but I was just curious. > > > Say you have the following URLs: > > >http://www.test.com/image.gif > >http://www.test.com/?src=image.gif?width=12 > > > I want to get the type of the image, i.e. the string gif. > > > For the first URL the regular expression .*\.([a-z]{3}) will do the > > trick while for the second one I am using .*=\([a-z]{3})?.*. > > > Ignoring the fact that the REs can be written better my question is: > > > If I put them together, that is write them as > > > .*\.([a-z]{3})|.*=\([a-z]{3})?.* > > > perl thinks that the or only applies to the characters immediately > > surrounding it (in this case ) and .). > > No. The alternation applies to the complete pattern '.*\.([a-z]{3})' OR
OK. So if I understood you correctly, given the following (actual) URLs http://beta.images.theglobeandmail.com/archive/01258/election_heads__1258993cl-3.jpg http://storage.canoe.ca/v1/dynamic_resize/?src=http://www.torontosun.com/news/decision2011/2011/04/06/300_harper_boring.jpg&size=248x186 the following pattern ^\s*.*\.([a-zA-z]{3})$ | ^\S*\?\S*\.([a-zA-z]{3})&.*$ should match them both. Am I correct? Regards, George > '.*=\([a-z]{3})?.*'. > > John > -- > Any intelligent fool can make things bigger and > more complex... It takes a touch of genius - > and a lot of courage to move in the opposite > direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/