[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: match finds wrong space.
From: |
Davide Brini |
Subject: |
Re: match finds wrong space. |
Date: |
Tue, 6 Jul 2010 23:05:19 +0100 |
On Tue, 6 Jul 2010 22:54:33 +0100 "Chris Willis" <address@hidden>
wrote:
> Hi
>
> another one, and pretty basic.
>
> The attached snippet sd respond "9 Mary Ann jane", rather than "5 Mary
> Ann jane" it actually responds with. In actual practice it was
> particularly difficult as the failure caused an infinite loop.
Depending on your locale, it's expected behavior, since [a-z] can match
"A" in some locales, strange as it may sound.
$ LC_ALL=en_US.utf8 awk 'BEGIN {
s = "Mary Ann jane"
n = match( s, /\040[a-z]/ )
print n, s }'
5 Mary Ann jane
$ LC_ALL=C awk 'BEGIN {
s = "Mary Ann jane"
n = match( s, /\040[a-z]/ )
print n, s }'
5 Mary Ann jane
If you don't want to set the locale, use [[:lower:]]:
$ awk 'BEGIN {
s = "Mary Ann jane"
n = match( s, /\040[[:lower:]]/ )
print n, s }'
9 Mary Ann jane
And btw, the versions of awk you're using are old. Latest is 3.1.8.
--
D.