[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

escape sequences for } { and $ in gsub

james Cunningham

12/27/2005 7:25:00 AM

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

1 Answer

lists

12/27/2005 8:44:00 AM

0

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