Date: Thu, 23 Jan 2014 15:44:56 -0800 From: <dteske@FreeBSD.org> To: "'Warren Block'" <wblock@wonkity.com>, "'Devin Teske'" <dteske@FreeBSD.org> Cc: 'RW' <rwmaillists@googlemail.com>, freebsd-questions@freebsd.org Subject: RE: awk programming question Message-ID: <04d201cf1895$20956890$61c039b0$@FreeBSD.org> In-Reply-To: <alpine.BSF.2.00.1401231537260.80613@wonkity.com> References: <F01EB9CE742DEB17DB6B51C7@localhost> <alpine.BSF.2.00.1401230900270.76961@wonkity.com> <20140123185604.4cbd7611@gumby.homeunix.com> <04a201cf1878$8ebce540$ac36afc0$@FreeBSD.org> <alpine.BSF.2.00.1401231346520.80613@wonkity.com> <04aa01cf187e$cfcf9ef0$6f6edcd0$@FreeBSD.org> <alpine.BSF.2.00.1401231537260.80613@wonkity.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> -----Original Message----- > From: Warren Block [mailto:wblock@wonkity.com] > Sent: Thursday, January 23, 2014 2:42 PM > To: 'Devin Teske' > Cc: 'RW'; freebsd-questions@freebsd.org > Subject: RE: awk programming question > > On Thu, 23 Jan 2014, dteske@FreeBSD.org wrote: > > > > > > >> -----Original Message----- > >> From: Warren Block [mailto:wblock@wonkity.com] > >> Sent: Thursday, January 23, 2014 12:57 PM > >> To: 'Devin Teske' > >> Cc: 'RW'; freebsd-questions@freebsd.org > >> Subject: RE: awk programming question > >> > >> On Thu, 23 Jan 2014, dteske@FreeBSD.org wrote: > >> > >>>> From: RW [mailto:rwmaillists@googlemail.com] > >>>> Note that awk supports +, but not newfangled things like *. > >>> > >>> With respect to regex, what awk really needs is the quantifier syntax... > >>> > >>> * = {0,} = zero or more > >>> + = {1,} = one or more > >>> {x,y} = any quantity from x inclusively up to y {x,} = any quantity > >>> from x or more > >> > >> I think RW meant to type that awk did not have the newfangled "?" for > >> non- greedy matches. > > > > But that one is supported. Tested on 9.2-R and 10.0-R... > > > > echo abbb | awk '{sub(/a?bbb/, ""); print}' # produces NULL output > > echo bbb | awk '{sub(/a?bbb/, ""); print}' # similarly produces NULL > > output > > > > Seems to be supported. But I'd really like to see {x,y} (the ? is > > equivalent to {0,1}). > > No, the non-greedy modifier to a standard quantifier: > > echo "abczabczabcz" | perl -ne '/(a.*z)/; print "$1\n"' > abczabczabcz > > echo "abczabczabcz" | perl -ne '/(a.*?z)/; print "$1\n"' > abcz Craziness! Wonder when that crept in. I'm not entirely sure how I feel about that -- in terms of readability, I'm not sure if the following is more readable: /(a[^z]*z)/ -- Devin _____________ The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?04d201cf1895$20956890$61c039b0$>