0

I have a variable a = "ver version" and v = "version". Now I want to replace 'ver' with 'version' using gsub.

Using gsub(v, "version", a) output is "version versionsion" I want it to be "version version". To replace exact string, I use "\\bpattern\\b"

gsub("\\bv\\b","version,a)

It says unexpected input. Can someone suggest the correct syntax for the same?

alistaire
  • 42,459
  • 4
  • 77
  • 117
Barry
  • 13
  • 5
  • If you are using `v`, then use `paste` i.e. `gsub(paste0("\b", v, "\b"), "version", a)` or just `gsub("\\bver\\b", "version", a)` (assuming that there could be multiple cases of 'ver') – akrun Nov 07 '16 at 06:07
  • thank you akrun, worked fine – Barry Nov 07 '16 at 06:11
  • 1
    @ZheyuanLi not the most authoritative source, but you're not the only one to think [g stands for global](http://stackoverflow.com/a/6124591/903061). – Gregor Thomas Nov 07 '16 at 06:34
  • Thank you! It had never occurred to me before and from now on I will always remember the difference between `sub` and `gsub` without having to look at the documentation. – Gregor Thomas Nov 07 '16 at 06:39

0 Answers0