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

Henrik Bengtsson hb at stat.berkeley.edu
Thu Mar 6 02:56:27 CET 2008


just curious, but does anyone know the source/reason of observing the
following error on OSX but not on WinXP and Linux?  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
[1] 1
> regexpr("[A-z]", "foo")
[1] 1
[1] 1

At least now I know it that the safest is to use '[a-zA-Z]' (or
possibly '[[:alpha:]]').


More information about the R-devel mailing list