Duncan Murdoch wrote:
On 11/16/2009 8:21 AM, Ottorino-Luca Pantani wrote:
Dear R users,
my problem today deals with my ignorance on regular expressions.
a matter I recently discovered.
You were close. First, gsub by default doesn't need escapes before
the parens. (There are lots of different conventions for regular
expressions, unfortunately.) So the Emacs regular expression V_\(.\)_
is entered as "V_(.)_" in the default version of gsub(). Second, to
enter a backslash into a string, you need to escape it. So the
replacement pattern V_0\1_ is entered as "V_0\\1_". So
gsub("V_(.)_", "V_0\\1_", foo)
should give you what you want.
actually, guessing from the form of the input, sub is more appropriate,
though the performance gain seems inessential (~3%).
vQ
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.