# Escape sequences for } { and $ in gsub

**URL:** <https://www.ruby-forum.com/t/escape-sequences-for-and-in-gsub/51150>\
**Category:** Ruby\
**Created:** [December 27, 2005, 8:28am UTC](https://www.ruby-forum.com/t/escape-sequences-for-and-in-gsub/51150 "2005-12-27T08:28:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![james\_Cunningham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@james\_Cunningham](https://www.ruby-forum.com/u/james_Cunningham)\
**Post date:** [December 27, 2005, 8:28am UTC](https://www.ruby-forum.com/t/escape-sequences-for-and-in-gsub/51150/1 "2005-12-27T08:28:24Z")

</div>

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 C.

---

<div class="post-metadata">

**Author:** ![james\_Cunningham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/b2d939/32.png) [@james\_Cunningham](https://www.ruby-forum.com/u/james_Cunningham)\
**Post date:** [December 27, 2005, 9:46am UTC](https://www.ruby-forum.com/t/escape-sequences-for-and-in-gsub/51150/2 "2005-12-27T09:46:29Z")

</div>

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
