Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 Feb 2001 12:41:07 -0300 (ART)
From:      Fernando Gleiser <fgleiser@cactus.fi.uba.ar>
To:        John Indra <john@office.naver.co.id>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: Crafting Perl RE...
Message-ID:  <Pine.BSF.4.21.0102091227490.18313-100000@cactus.fi.uba.ar>
In-Reply-To: <20010209160849.A97806@office.naver.co.id>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi

first, excuse my bad english.

The problem is that the star is greedy, it will attempt to match as
much as posible (that is, up to second dot rigth to left).
if you want to capture the extension of the file (that is, the string
which follows the last dot), just say so:

$string=~ m/\.([^.]+)$/;

which says: a dot, followed by one or more of any non-dot caracters up to
the end of the string.

Be *very careful* when using the star cuantifier, because you can get nasty 
surprises (hint: .* allways match)

Take a look at "mastering regular  expresions" by Jeffrey E. Friedl,
it is the best book on RE.

On Fri, 9 Feb 2001, John Indra wrote:

> Hi...
> 
> Simple question but I don't know the answer. Suppose I have this string:
> somefile.ins.jpg. I want to craft a Perl RE so it captures the jpg part. I
> try this RE:
> 
> $string =~ m#\.(.*)$#
> 
> Unfortunately $1 captures ins.jpg, not jpg as I want.
> 
> What RE to get it right?
> 
> Thanks...
> 
> /john
> 
> 
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-questions" in the body of the message
> 



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0102091227490.18313-100000>