Re: Crafting Perl RE...

[ Available lists | Index of freebsd-questions | Month of Feb 2001 | Week of 9 Feb 2001 | Raw email | View thread | Wrap long lines | Reply | Tag ]
From
Jan Grant <Jan.Grant@bristol.ac.uk>
Date
9 Feb 2001 03:47:35
Subject
Re: Crafting Perl RE...
Message-ID
Pine.GSO.4.31.0102091145380.14282-100000@mail.ilrt.bris.ac.uk

In reply to
Referenced by

[ Hide this part ]
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



Elapsed time: 0.422 seconds