# Gsub ignorecase unicode

**URL:** <https://www.ruby-forum.com/t/gsub-ignorecase-unicode/122819>\
**Category:** Rails\
**Created:** [December 12, 2007, 3:45pm UTC](https://www.ruby-forum.com/t/gsub-ignorecase-unicode/122819 "2007-12-12T15:45:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ferro\_i](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6a8cbe/32.png) [@ferro\_i](https://www.ruby-forum.com/u/ferro_i)\
**Post date:** [December 12, 2007, 3:45pm UTC](https://www.ruby-forum.com/t/gsub-ignorecase-unicode/122819/1 "2007-12-12T15:45:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ferro\_i](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6a8cbe/32.png) [@ferro\_i](https://www.ruby-forum.com/u/ferro_i)\
**Post date:** [December 12, 2007, 7:42pm UTC](https://www.ruby-forum.com/t/gsub-ignorecase-unicode/122819/2 "2007-12-12T19:42:38Z")

</div>

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](http://www.ruby-forum.com/topic/133538)

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

---

<div class="post-metadata">

**Author:** ![ferro\_i](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6a8cbe/32.png) [@ferro\_i](https://www.ruby-forum.com/u/ferro_i)\
**Post date:** [December 13, 2007, 9:00am UTC](https://www.ruby-forum.com/t/gsub-ignorecase-unicode/122819/3 "2007-12-13T09:00:44Z")

</div>

> $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
