escape sequences for } { and $ in gsub

J

james Cunningham

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
 
L

lists

james said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top