Forum: Ruby escape sequences for } { and $ in gsub

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
14add0e081696a4fc8ab4bb747395eb7?d=identicon&s=25 james Cunningham (Guest)
on 2005-12-27 08:28
(Received via mailing list)
I've found an older thread regarding escape sequences and gsub - but I
did not understand all of the explanation. I am trying to replace the
following string portion

\$\symbol{92}

with

$

and from the older thread it looks as if something like the following
is required:

gsub!(/\\$$\\symbol{{92}}/,'$')

after about three hours of fiddling with the above expression the best
I've obtained has been with

gsub!(/\\symbol{92/,'$')

but this does not solve the substitution problem. I must be using the
wrong escape sequence for $ and }.

Does anyone have any recommendations or pointers to documentation on
escape sequences and gsub? Thank you in advance for your advice.

best regards, James Cunningham
E6cd9eab032b40b10c621e186133ff53?d=identicon&s=25 unknown (Guest)
on 2005-12-27 09:46
(Received via mailing list)
james Cunningham wrote:
 > I've found an older thread regarding escape sequences and gsub - but
I
 > did not understand all of the explanation. I am trying to replace the
 > following string portion
 >
 > \$\symbol{92}
 >
 > with
 >
 > $
 >

is this what you need?

b = "WWWW\\$\\symbol{92}KKKK"
puts b.gsub(/\\\$\\symbol\{92\}/, '$')

 >WWWW$KKKK

just escape the
    \
    $
    {
    }

with a \ each.

or, don't use regular expressions:

puts b.gsub('\\$\\symbol{92}', '$')



hope this helps
-ramil
This topic is locked and can not be replied to.