Date: Fri, 9 Feb 2001 11:46:51 +0000 (GMT) From: Jan Grant <Jan.Grant@bristol.ac.uk> To: John Indra <john@office.naver.co.id> Cc: freebsd-questions <freebsd-questions@freebsd.org> Subject: Re: Crafting Perl RE... Message-ID: <Pine.GSO.4.31.0102091145380.14282-100000@mail.ilrt.bris.ac.uk> In-Reply-To: <20010209160849.A97806@office.naver.co.id>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.31.0102091145380.14282-100000>