Problem with regular expression

Hi

str = “тратата @rails” # (UTF-8)
str.gsub(/(@rails)/) { |m| “>#{$1}<” }
=> “тратата >@rails<”
str.gsub(/(@rails)$/) { |m| “>#{$1}<” }
=> “тратата >@rails<”
str.gsub(/(@rails)[$]/) { |m| “>#{$1}<” }
=> “тратата @rails
str.gsub(/(@rails)[\s$]/) { |m| “>#{$1}<” }
=> “тратата @rails

Where I’ve got mistake? This is work correctly on rubular.com

ruby 1.9.2

$ inside [] recognized just as literal ‘$’, not the end of the line:

"тратата @rails"[/(@rails)[$]/]    # => nil
"тратата @rails$"[/(@rails)[$]/]   # => "@rails$"

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs