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