awk programming question
Warren Block
wblock at wonkity.com
Fri Jan 24 02:22:57 UTC 2014
On Thu, 23 Jan 2014, dteske at FreeBSD.org wrote:
>> 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've been using it for at least a decade, so it's probably been around
at least twice that long. ...So probably came out about twenty years
after the sed and awk feature sets were frozen. :)
> 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)/
Wait till you see the other PCRE stuff. There are lots of things that
really make it much more powerful. perlre(1) covers it all, sketchily
and not really in order.
I've said elsewhere, and will repeat again: "Mastering Regular
Expressions" by Jeffrey E. F. Friedl (the owl book) is amazing. My
first edition (1997) does not have some of the newer Perl stuff, but
it's now up to a third edition:
http://shop.oreilly.com/product/9780596528126.do
More information about the freebsd-questions
mailing list