I'm trying to strip non-word characters from the beginning and end of a string. The function I've got so far is:
$KCODE='UTF-8'
...
def clean_string str
str && str.gsub(/\s+/msiu, ' ').gsub(/\A\W*|\W*\Z/msiu,'')
end
It works in most cases, but it's failing on pound signs.
>> puts clean_string('£5.00')
£5.00
I've read that in ruby 1.8 this is per-spec behaviour; that all non-ascii characters are considered to be word characters. But it's not the behaviour I want; I want only word characters to be considered to be word characters, as they are in ruby 1.9.
Is there a way to get ruby 1.9 unicode regex behaviour in ruby 1.8 (with rails 2.3.10)?