From owner-freebsd-questions Fri Feb 9 3:47:35 2001 Delivered-To: freebsd-questions@freebsd.org Received: from dire.bris.ac.uk (dire.bris.ac.uk [137.222.10.60]) by hub.freebsd.org (Postfix) with ESMTP id 997A937B6B8 for ; Fri, 9 Feb 2001 03:47:17 -0800 (PST) Received: from mail.ilrt.bris.ac.uk by dire.bris.ac.uk with SMTP-PRIV with ESMTP; Fri, 9 Feb 2001 11:47:11 +0000 Received: from cmjg (helo=localhost) by mail.ilrt.bris.ac.uk with local-esmtp (Exim 3.16 #1) id 14RC0p-0003rK-00; Fri, 09 Feb 2001 11:46:51 +0000 Date: Fri, 9 Feb 2001 11:46:51 +0000 (GMT) From: Jan Grant To: John Indra Cc: freebsd-questions 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 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? man perlre; you're looking for the section that starts By default, a quantified subpattern is "greedy", that is, it will match as many times as possible (given a particular starting location) while still allowing the rest of the pattern to match. If you want it to match the minimum number of times possible, follow the quantifier with a "?". Note that the meanings don't change, just the "greediness": in other words, use \.(.*?)$ -- jan grant, ILRT, University of Bristol. http://www.ilrt.bris.ac.uk/ Tel +44(0)117 9287163 Fax +44 (0)117 9287112 RFC822 jan.grant@bris.ac.uk Donate a signature: http://tribble.ilrt.bris.ac.uk/~cmjg/sig-submit To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message