From owner-freebsd-questions@FreeBSD.ORG Fri Jun 25 18:50:52 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 40E291065673 for ; Fri, 25 Jun 2010 18:50:52 +0000 (UTC) (envelope-from parv@pair.com) Received: from hrndva-omtalb.mail.rr.com (hrndva-omtalb.mail.rr.com [71.74.56.124]) by mx1.freebsd.org (Postfix) with ESMTP id E90798FC19 for ; Fri, 25 Jun 2010 18:50:51 +0000 (UTC) X-Authority-Analysis: v=1.1 cv=CRXretTPUtnO3YxfLBAQPdv2BUzevxUrVWgTW+Y28TY= c=1 sm=0 a=RWmFJ1rmKfAA:10 a=UBIxAjGgU1YA:10 a=kj9zAlcOel0A:10 a=64iin7ZDX+lUS8OB6KzQoA==:17 a=ePsyhcdrAAAA:8 a=Ymsr-CWnAAAA:8 a=2HPld2HDaiCIpCuGDsIA:9 a=c8jR33Z-LgVyLZMjUUgN1icxsckA:4 a=CjuIK1q_8ugA:10 a=v2EulsF24l4A:10 a=O_fR4ZySa72RO1si:21 a=FXADqR1PTEihRDX1:21 a=64iin7ZDX+lUS8OB6KzQoA==:117 X-Cloudmark-Score: 0 X-Originating-IP: 98.150.184.250 Received: from [98.150.184.250] ([98.150.184.250:54596] helo=localhost.hawaii.res.rr.com) by hrndva-oedge04.mail.rr.com (envelope-from ) (ecelerity 2.2.2.39 r()) with ESMTP id 23/4E-25793-A8AF42C4; Fri, 25 Jun 2010 18:50:51 +0000 Received: from holstein.holy.cow (parv [127.0.0.2]) by localhost.hawaii.res.rr.com (Postfix) with ESMTP id D75965C94; Fri, 25 Jun 2010 08:54:00 -1000 (HST) Received: (from parv@localhost) by holstein.holy.cow (8.14.3/8.14.3/Submit) id o5PIrxor005687; Fri, 25 Jun 2010 08:53:59 -1000 (HST) (envelope-from parv@pair.com) X-Authentication-Warning: holstein.holy.cow: parv set sender to parv@pair.com using -f Date: Fri, 25 Jun 2010 08:53:59 -1000 From: parv@pair.com To: freebsd-questions@freebsd.org, Carl Johnson Message-ID: <20100625185359.GA1821@holstein.holy.cow> Mail-Followup-To: freebsd-questions@freebsd.org, Carl Johnson References: <4C22B3D7.6070102@comclark.com> <20100624033257.2D074BEA6@kev.msw.wpafb.af.mil> <87lja4mlme.fsf@cjlinux.localnet> <87hbksmk6y.fsf@cjlinux.localnet> <87d3vgmj1s.fsf@cjlinux.localnet> <20100624183407.GA49923@holstein.holy.cow> <20100624183933.GA50443@holstein.holy.cow> <20100624192256.GF557@libertas.local.camdensoftware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100624192256.GF557@libertas.local.camdensoftware.com> Cc: Subject: Re: check for numeric content in a shell script (FreeBSD sh) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Jun 2010 18:50:52 -0000 in message <20100624192256.GF557@libertas.local.camdensoftware.com>, wrote Chip Camden thusly... > > On Jun 24 08:39, Parv wrote: > > in message <20100624183407.GA49923@holstein.holy.cow>, > > wrote parv@pair.com thusly... > > > > > > # Matches a number, either positive (without '+' sign) or > > > # negative, which is either a whole number; or a real number > > > # ending with decimal point, or a real number with or without > > > # leading digits before the decimal point. > > . ^ > > . ^ plural > > > ^ > > > -? > > > ( > > > [0-9] [.]? [0-9]* > > > | > > > [0-9]? [.] [0-9]+ > > . ^ > > . ^ oops > > > > Please change the immediately above regex portion to ... > > > > [0-9]* [.] [0-9]+ ... > We still need to be able to handle numbers without a decimal. First alternative above handles that ... [0-9] # Match 1 digit, [.]? # followed by an optional decimal, [0-9]* # followed by any number of optional digits. > Try this: > > [0-9]*\.?[0-9]+ If it is really /^[0-9]*\.?[0-9]+$/, then it does not match a negative number or a number ending with a decimal (e.g. 8.). > The question mark says "0 or 1" > > > > > ) > > > $ Annotated regex now is ... ^ # Anchor at the beginning of string; -? # followed by an optional -ve sign; ( # start grouping|alternatives; [0-9] # match 1 digit, [.]? # followed by an optional decimal, [0-9]* # followed by any number of optional digits; | # OR, [0-9]* # match any number of optional digits, [.] # followed by 1 decimal point, [0-9]+ # followed by 1 or more digits; ) # end of grouping; $ # anchor at the end of the string. - parv --