Skip to content
Prev 200394 / 398502 Next

on gsub (simple, but not to me!) sintax

On 11/16/2009 8:21 AM, Ottorino-Luca Pantani wrote:
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.

Duncan Murdoch