Escape sequences for } { and $ in gsub


#1

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.


#2

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