From murdoch at stats.uwo.ca  Thu Mar  6 03:18:34 2008
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Wed, 05 Mar 2008 21:18:34 -0500
Subject: [Rd] invalid regular expression '[a-Z]'
In-Reply-To: <59d7961d0803051756s307dcab1kbaffc4eeb9d308cf@mail.gmail.com>
References: <59d7961d0803051756s307dcab1kbaffc4eeb9d308cf@mail.gmail.com>
Message-ID: <47CF547A.5020203@stats.uwo.ca>

On 05/03/2008 8:56 PM, Henrik Bengtsson wrote:
> Hi,
> 
> just curious, but does anyone know the source/reason of observing the
> following error on OSX but not on WinXP and Linux? 

Presumably in the locale you're using on OSX, "a" < "Z" is false.  This 
is the ascii sort order used in the C locale.  On my Windows box, "a" < 
"Z" is true, because it uses the English_Canada.1252 collation order.

Duncan Murdoch

  I've tried with a
> few different versions of R (v2.5.1, v2.6.1, v2.6.2, v2.7.0devel).
> The locale does not seem to affect the error, i.e. I've tested a few
> different and it is still only OSX that gives the error but not the
> other two.
> 
>> regexpr("[a-Z]", "foo")
> Error in regexpr(pattern, text, extended, fixed, useBytes) :
>         invalid regular expression '[a-Z]'
>> regexpr("[a-zA-Z]", "foo")
> [1] 1
> attr(,"match.length")
> [1] 1
>> regexpr("[A-z]", "foo")
> [1] 1
> attr(,"match.length")
> [1] 1
> 
> At least now I know it that the safest is to use '[a-zA-Z]' (or
> possibly '[[:alpha:]]').
> 
> /Henrik
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] invalid regular expression '[a-Z]'
Duncan Murdoch