2

I have a macruby project in xcode, in which I want to replace all the left and right quotes in a string with ~@@~@@~" and "~@@~@@~, respectively. I tested the following code in rubular.com, and it works correctly.

string.gsub!(/\B"/, "~@@~@@~\"")
string.gsub!(/\b"/, "\"~@@~@@~")

But when I use this in xcode, it interprets the " in the regexp as the beginning of the string, and says I have the wrong numer of arguments for gsub. I tried escaping the quote:

string.gsub!(/\B\"/, "~@@~@@~\"")
string.gsub!(/\b\"/, "\"~@@~@@~")

But that also did not work. Thanks for your help.

EDIT: I managed to get the error to go away, it seems it was due to something else. The highlighting is still off, but I can handle that, since it works.

sawa
  • 165,429
  • 45
  • 277
  • 381
V9801
  • 375
  • 2
  • 11

1 Answers1

0

Does the alternate syntax %r[\B\"] work any better? What about Regexp.new given a string?

tadman
  • 208,517
  • 23
  • 234
  • 262