gsub UTF values

C

ciapecki

please help me how to solve following replaceing: \\char_code into
\char_code

having string2 = "\\303\\274" I want to get string = "\303\274", so
that after calling puts on this string I will get special character and
not the number of this special character

irb(main):001:0> string2 = "\\303\\274"
=> "\\303\\274"
irb(main):002:0> puts string2
\303\274
=> nil

I can do so:
irb(main):003:0> puts string2.gsub('\\303\\274',"\303\274").inspect
"\303\274"
=> nil

and so:
irb(main):004:0> puts string2.gsub(/\\\d{3}\\\d{3}/,"\303\274").inspect
"\303\274"
=> nil

but when I want to replace every occurance of any 3 digit number
comming after '\' sign it does not work as I expect:
irb(main):005:0> puts string2.gsub(/\\\d{3}\\\d{3}/,'\\1\\2').inspect
""
=> nil

can anybody tell me how to replace those backslashes?
thanks
chris
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top