aris
1
So I am looking at the Ruby API for sub and gsub from here:
I copied and pasted
“hello”.sub(%r[aeiou]/, ‘*’)
“hello”.sub(%r([aeiou])/, ‘<\1>’)
and to my surprise, they both result in an error.
1.9.3p194 :003 > “hello”.sub(%r[aeiou]/, ‘')
SyntaxError: (irb):3: syntax error, unexpected ‘,’
“hello”.sub(%r[aeiou]/, '’)
^
(irb):3: syntax error, unexpected ‘)’, expecting $end
from /home/zrun/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `’
Why?
Hi,
There’s no opening / delimiter for the %r syntax:
“hello”.sub(%r/[aeiou]/, ‘*’)
And if you’re using / delimiters anyway, you can just leave out the %r:
“hello”.sub(/[aeiou]/, ‘*’)
So this means there is an error in the API?
On Sat, Jun 9, 2012 at 8:32 AM, Daniel B. [email protected] wrote:
So this means there is an error in the API?
Where exactly did you copy this broken example from?
I see nothing like it here
Hassan S. wrote in post #1063853:
Where exactly did you copy this broken example from?
He already put the link up in the first post:
sub and gsub are methods of String, not of Regexp.
On Sat, Jun 9, 2012 at 11:14 AM, Jan E. [email protected] wrote:
He already put the link up in the first post:
Class: String (Ruby 1.9.3)
? There’s nothing like that in the email I’m looking at, hence my
question 
sub and gsub are methods of String, not of Regexp.
True, but since the question was about regex syntax, it seemed an
obvious place to look, in the absence of any other information.
In any case, the answer is apparently yes, the String doc is wrong 