Skip to content

toupper does not work in sub + regex

2 messages · Tan, Richard, Gabor Grothendieck

#
sub only handles replacement strings, not replacement functions.
Your code is the same as:

sub("q_([a-z])[a-zA-Z]*", '\\1', "q_sviRaw")

since toupper('\\1') has no alphabetics so its just literally '\\1' and
the latter is what sub uses.

The gsubfn function in the gsubfn package can deal with replacement
functions:
[1] "S"

See the home page: http;//gsubfn.googlecode.com, vignette and help page.
On Mon, Apr 13, 2009 at 11:54 AM, Tan, Richard <RTan at panagora.com> wrote: