develooper Front page | perl.beginners | Postings from April 2011

Re: Regular Expressions Question

Thread Previous | Thread Next
From:
John W. Krahn
Date:
April 10, 2011 15:03
Subject:
Re: Regular Expressions Question
Message ID:
4DA22948.3090706@shaw.ca
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 
'.*=\([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

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About