Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 2 Oct 2000 19:15:37 +0100
From:      Mark Ovens <marko@freebsd.org>
To:        Christopher Rued <c.rued@xsb.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Perl question
Message-ID:  <20001002191537.G252@parish>
In-Reply-To: <14808.52583.347797.384055@chris.xsb.com>; from c.rued@xsb.com on Mon, Oct 02, 2000 at 02:01:11PM -0400
References:  <14808.52583.347797.384055@chris.xsb.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Oct 02, 2000 at 02:01:11PM -0400, Christopher Rued wrote:
> I realize that this is not really a FreeBSD question, but I like this
> mailing list and the answers that are sent to it :).
> 
> My question is:
>   How do I have perl return me the first and only the first match to a
> regular expression?  I know that I can return /all/ matches to an
> array, and get the first one, but I only want to have it evaluate as
> far as the first match and then stop.
> 
> For example, given the string xayxbyxcy and the regular expression
> x.y, I want it to return to me only xay and not evaluate any further.
> 

/x.?y/

From Learning Perl:

	"We can force any multiplier to be non-greedy (or lazy) by
	following it with a question mark:

		$_ = "a xxx c xxxxxxxxx c xxx d";
		/a.?c.*d/;

	Here, the a.*?c now matches the fewest characters between the a and
	he c, not the most characters. This means that the leftmost c
	ismatched, not the rightmost....."

> Thanks in advance.
> 
> -- 
> 					-Chris Rued
> 
> 
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-questions" in the body of the message

-- 
		4.4 - The number of the Beastie
________________________________________________________________
51.44°N  FreeBSD - The Power To Serve http://www.freebsd.org
2.057°W  My Webpage http://ukug.uk.freebsd.org/~mark
mailto:marko@freebsd.org                http://www.radan.com



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?20001002191537.G252>