From owner-freebsd-questions Mon Oct 2 11:16: 1 2000 Delivered-To: freebsd-questions@freebsd.org Received: from mta06-svc.ntlworld.com (mta06-svc.ntlworld.com [62.253.162.46]) by hub.freebsd.org (Postfix) with ESMTP id 5977237B502 for ; Mon, 2 Oct 2000 11:15:55 -0700 (PDT) Received: from parish ([62.253.85.160]) by mta06-svc.ntlworld.com (InterMail vM.4.01.02.27 201-229-119-110) with ESMTP id <20001002181551.ELQL19246.mta06-svc.ntlworld.com@parish>; Mon, 2 Oct 2000 19:15:51 +0100 Received: (from mark@localhost) by parish (8.11.0/8.11.0) id e92IFbU02137; Mon, 2 Oct 2000 19:15:37 +0100 (BST) (envelope-from mark) Date: Mon, 2 Oct 2000 19:15:37 +0100 From: Mark Ovens To: Christopher Rued Cc: freebsd-questions@freebsd.org Subject: Re: Perl question Message-ID: <20001002191537.G252@parish> References: <14808.52583.347797.384055@chris.xsb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.2.5i 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 Organization: Total lack of Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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