From owner-freebsd-questions Fri Feb 9 8:30: 8 2001 Delivered-To: freebsd-questions@freebsd.org Received: from cactus.fi.uba.ar (cactus.fi.uba.ar [157.92.49.108]) by hub.freebsd.org (Postfix) with ESMTP id 6827D37BBBD for ; Fri, 9 Feb 2001 07:36:46 -0800 (PST) Received: from cactus.fi.uba.ar (cactus.fi.uba.ar [157.92.49.108]) by cactus.fi.uba.ar (8.9.3/8.9.3) with ESMTP id MAA20409; Fri, 9 Feb 2001 12:41:07 -0300 (ART) (envelope-from fgleiser@cactus.fi.uba.ar) Date: Fri, 9 Feb 2001 12:41:07 -0300 (ART) From: Fernando Gleiser To: John Indra Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Crafting Perl RE... In-Reply-To: <20010209160849.A97806@office.naver.co.id> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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