Gsub ignorecase unicode

Hey guys

‘öçğüş’.chars.upcase => “ÖÇĞÜŞ” work perfectly

How do you gsub the special characters (åäöü)?
I use utf-8 rails 1.2.

“AÖŞaöş”.chars.gsub(/([aöş])/i, ’ •\1• ')
=> •A• ÖŞ •a• •ö• •ş•

gsub not work in unicode characters

How did you solve this problem?

Ferit

On Dec 12, 2007, at 6:45 AM, Ferit Öztosun wrote:

How did you solve this problem?

I spent several days working on this and finally managed to piece
together some help from the ruby list. If you’re into understanding
it all, try this thread: Unicode in Regex - Ruby - Ruby-Forum

First, make sure you have this line at the top of your environment.rb
file:

$KCODE = ‘UTF8’

Next, make sure your regex ends with /u as in /\w+/u

Finally, this is how you specify UTF-8 characters:

‘üéåë’.gsub(/#{“\303\253”}/u, ‘x’)

Ranges would like /#{“\303\200”}-#{“\303\226”}/u

You have to use the octal numbers, so that one above would replace ë
with x.


def gw
acts_as_n00b
writes_at(www.railsdev.ws)
end

$KCODE = ‘UTF8’

Next, make sure your regex ends with /u as in /\w+/u

Finally, this is how you specify UTF-8 characters:

‘üéåë’.gsub(/#{"\303\253"}/u, ‘x’)

Ranges would like /#{"\303\200"}-#{"\303\226"}/u

You have to use the octal numbers, so that one above would replace ë
with x.

Sory i explained missing

i can do already unicode in regex

example: ‘üéåëË’.gsub(/ë/, ‘x’)
=> üéåxË

but i want to unicode with ignorecase /i
because search result must be with bold

example: ‘üéåËafe’.gsub(/(åë)/i, ‘\1
result must be like => “üéåËafe”, but ignorecase not work

‘ë’.chars.upcase => “Ë” work perfectly