From: Nathan Beyer Date: 2012-12-25T13:28:43+09:00 Subject: Re: Character encoding in 1.9 --bcaec54ee8002cdaa204d1a5a693 Content-Type: text/plain; charset=UTF-8 Check out the Regexp documentation, specifically the 'new'/'compile' method: http://www.ruby-doc.org/core-1.9.3/Regexp.html#method-c-new. I think you'll need to use Regexp.compile to create an "encoding-less" regular expression. I would guess something like this - [3,4,5,6,7].each do |n| line.gsub!(Regexp.compile('\377\37' + n.to_s + '\001', nil, 'n'),"") end You'll have to fiddle with it, as I didn't have a chance to test it out to see if this actually works. I'd have to know the encoding the 'line' variable to accurately test it anyway. On Mon, Dec 24, 2012 at 2:34 PM, Andrew S. wrote: > I have some code in 1.8 that would strip certain special characters out > of a string (escape sequences in Telnet specifically, such as > \377\373\001). > > I've moved to 1.9 and now that code fails with "invalid multibyte > escape". > > I've looked at some of the tutorials regarding encodings in 1.9 and to > be honest I find them very intimidating. I'm hoping someone can suggest > a quick fix? > > Here's the code: > > [3,4,5,6,7].each do |n| > line.gsub!(/#{('\377\37' + n.to_s + '\001')}/,"") > end > > Many thanks in advance! > > - Andrew > > -- > Posted via http://www.ruby-forum.com/. > > --bcaec54ee8002cdaa204d1a5a693 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Check out the Regexp documentation, specifically the '= new'/'compile' method:=C2=A0http://www.ruby-doc.org/core-1.9.3/Reg= exp.html#method-c-new. I think you'll need to use Regexp.compile to= create an "encoding-less" regular expression.

I would guess something like this -
[3,4,5,6,7].each do |n|
=C2=A0 =C2=A0 l= ine.gsub!(Regexp.compile('\377\37' + n.to_s + '\001', nil, = 'n'),"")
end
<= /div>

You'll have to fiddle with it, as I didn't have a cha= nce to test it out to see if this actually works. I'd have to know the = encoding the 'line' variable to accurately test it anyway.


On Mon,= Dec 24, 2012 at 2:34 PM, Andrew S. <lists@ruby-forum.com> wrote:
I have some code in 1.8 that would strip cer= tain special characters out
of a string (escape sequences in Telnet specifically, such as
\377\373\001).

I've moved to 1.9 and now that code fails with "invalid multibyte<= br> escape".

I've looked at some of the tutorials regarding encodings in 1.9 and to<= br> be honest I find them very intimidating. =C2=A0I'm hoping someone can s= uggest
a quick fix?

Here's the code:

[3,4,5,6,7].each do |n|
=C2=A0 =C2=A0 line.gsub!(/#{('\377\37' + n.to_s + '\001')}/= ,"")
end

Many thanks in advance!

=C2=A0- Andrew

--
Posted via http://= www.ruby-forum.com/.


--bcaec54ee8002cdaa204d1a5a693--