bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] lower case using [a-z] version 3.1.5


From: Davide Brini
Subject: Re: [bug-gawk] lower case using [a-z] version 3.1.5
Date: Sat, 5 Nov 2011 10:34:39 +0100
User-agent:

On Fri, 04 Nov 2011 19:47:03 -0400, Mark Wambach <address@hidden> wrote:

> The following doesn't work:
> 
> echo "AasdfasfJ" | gawk 'BEGIN{IGNORECASE=0;} 
> $1 ~ /^A[a-z]+$/ { print; }'
> 
> The following does work:
> echo "AasdfasfJ" | gawk 'BEGIN{IGNORECASE=0;} 
> $1 ~ /^A[[:lower:]]+$/ { print; }'

This (correctly) doesn't work for me with gawk 4.
 
> The 2nd one warns me about IGNORECASE being a gawk extension:
> echo "Aasdfasf" | gawk -W lint 'BEGIN{IGNORECASE=0;} $1 ~ /^A[[:lower:]]+$/ { 
> print; }'
> gawk: warning: `IGNORECASE' is a gawk extension
> Aasdfasf
> 
> It seems to be broken.  Am I missing something?

First, I'm not sure why you're setting IGNORECASE to 0, which is the default
anyway.

Second, the first two examples above are different from the third one; in
the first two, you have a trailing "J" which is missing in the third one,
so [[:lower:]]+$ can't match, and neither can [a-z]+$ (although the latter
might match uppercase letters under certain circumstances, it looks like
it's not happening to you here).

The third one works because you don't have the trailing "J" in the string.
 
> On SunOS 5.10
> address@hidden>echo "AasdfasfJ" | awk 'BEGIN{IGNORECASE=0;} 
> $1 ~ /^A[a-z]+$/ { print; }'
> address@hidden>echo "Aasdfasf" | awk 'BEGIN{IGNORECASE=0;} 
> $1 ~ /^A[a-z]+$/ { print; }'
> Aasdfasf
> 
> This is what I would have expected.

That is correct; in the first case you have the trailing "J" so [a-z]+$
doesn't match, while in the second case you don't have it so [a-z]+$
matches and the line is printed.

The same happens with gawk 4:

$ echo "AasdfasfJ" | awk 'BEGIN{IGNORECASE=0;} $1 ~ /^A[a-z]+$/ { print; }'
$ echo "Aasdfasf" | awk 'BEGIN{IGNORECASE=0;} $1 ~ /^A[a-z]+$/ { print; }'
Aasdfasf

I'm not sure what you think is wrong in what you're seeing.

-- 
D.



reply via email to

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