tags:

views:

39

answers:

1

Hi,

I am trying to replace a non ASCII character from a string with the following code:

string.gsub(194.chr,'')

When I do this, I get the following error:

RegexpError: premature end of regular expression: /�/

Can anyone tell me how to achieve this?

Thanks

Paul

+1  A: 
>> string="foo\xC2bar"
=> "foo\xC2bar"
>> string.force_encoding"ASCII-8BIT"
=> "foo\xC2bar"
>> string.gsub(194.chr, '')
=> "foobar"
gnibbler
so what's the principle here, that this is necessary?
rogerdpack
@roger, The original string object is utf-8 encoded. It doesn't make sense to mix ascii and unicode like this. I think gsub is trying to encode 194.chr to utf-8 before applying the regex, and this is failing because it is not a complete utf-8 character
gnibbler