bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: {} operators don't work with match


From: Stepan Kasal
Subject: Re: {} operators don't work with match
Date: Thu, 20 Oct 2005 17:51:23 +0200
User-agent: Mutt/1.4.1i

Hello,

> In GNU Awk 3.1.1 on Fedora 3, if I try:
> 
> echo "-6410" | gawk '{match($0, /-.*(.{1,3})..$/, arr);print arr[1]}'
> 
> I get nothing, when I would expect "64". match seems not to like the {} 
> operator.

first, {..} is not on by default, you have to use gawk option
--re-interval or --posix to switch it on.

With my gawk 3.1.4, I use:

$ echo "-6410" | gawk --re-interval '{match($0, /-.*(.{1,3})..$/, arr);print 
arr[1]}'
4

And indeed, "4" is the right answer, as the ".*" before the parentheses is
greedy, so it matches as much as possible.

HTH,
        Stepan Kasal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]