Re: [Rd] pb in regular expression with the character "-" (PR#9437)

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Thu 04 Jan 2007 - 10:42:23 GMT

Why do you think this is a bug in R? You have not told us what you expected, but the character range |-| contains only | . Not agreeing with your expectations (unstated or otherwise) is not a bug in R.

\- is the same as -, and - is special in character classes. (If it is first or last it is treated literally.) And | is not a metacharacter inside a character class. Also,

> grep("[d\\-c]", c("a-a","b"))
[1] 1 2
> grep("[d\\-c]", c("a-a","b"), perl=TRUE)
[1] 1

shows that escaping - works only in perl (which you will find from the background references mentioned, e.g.

   The interpretation of an ordinary character preceded by a backslash    ('\') is undefined.

.)

This is all carefully documented in ?regexp, e.g.

      Patterns are described here as they would be printed by 'cat': do
      remember that backslashes need to be doubled in entering R
      character strings from the keyboard.


This is not the first time you have wasted our resources with false bug reports, so please show more respect for the R developers' time. You were also explicitly asked not to report on obselete versions of R.

On Wed, 3 Jan 2007, xiao.gang.fan1@libertysurf.fr wrote:

> Full_Name: FAN
> Version: 2.4.0
> OS: Windows
> Submission from: (NULL) (159.50.101.9)
>
>
> These are expected:
>
>> grep("[\-|c]", c("a-a","b"))
> [1] 1
>
>> gsub("[\-|c]", "&", c("a-a","b"))
> [1] "a&a" "b"
>
> but these are strange:
>
>> grep("[d|\-|c]", c("a-a","b"))
> integer(0)
>
>> gsub("[d|\-|c]", "&", c("a-a","b"))
> [1] "a-a" "b"
>
> Thanks
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Thu Jan 04 21:49:01 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 04 Jan 2007 - 21:31:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.