# Win32 ruby1.9 regexp and cyrillic string

**URL:** <https://www.ruby-forum.com/t/win32-ruby1-9-regexp-and-cyrillic-string/187668>\
**Category:** Ruby\
**Created:** [April 27, 2010, 4:29pm UTC](https://www.ruby-forum.com/t/win32-ruby1-9-regexp-and-cyrillic-string/187668 "2010-04-27T16:29:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![karevn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/c68b51/32.png) [@karevn](https://www.ruby-forum.com/u/karevn)\
**Post date:** [April 27, 2010, 4:29pm UTC](https://www.ruby-forum.com/t/win32-ruby1-9-regexp-and-cyrillic-string/187668/1 "2010-04-27T16:29:12Z")

</div>

#coding: utf-8  
str2 = “asdfÐœÐ¸ÐºÐ¸Ð¼Ð°ÑƒÑ”  
p str2.encoding #Encoding:UTF-8  
p str2.scan /\p{Cyrillic}/ #found all cyrillic charachters  
str2.gsub!(/\w/u,‘’) #removes only latin characters  
puts str2

The question is why /\w/ ignore cyrillic characters?

I have installed latest ruby package from [http://rubyinstaller.org/](http://rubyinstaller.org/).  
Here is my output of ruby -v  
ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-mingw32]

---

<div class="post-metadata">

**Author:** ![karevn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/c68b51/32.png) [@karevn](https://www.ruby-forum.com/u/karevn)\
**Post date:** [April 27, 2010, 6:55pm UTC](https://www.ruby-forum.com/t/win32-ruby1-9-regexp-and-cyrillic-string/187668/2 "2010-04-27T18:55:22Z")

</div>

> str2.gsub!(/\w/u,’’) #removes only latin characters

> The question is why /\w/ ignore cyrillic characters?

Are cyrillic characters supposed to count as “word characters”? (\w) ?  
If so then looks like a bug to me. Ping core.  
-rp

---

<div class="post-metadata">

**Author:** ![karevn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/c68b51/32.png) [@karevn](https://www.ruby-forum.com/u/karevn)\
**Post date:** [April 27, 2010, 7:20pm UTC](https://www.ruby-forum.com/t/win32-ruby1-9-regexp-and-cyrillic-string/187668/3 "2010-04-27T19:20:33Z")

</div>

Nikolay K. wrote:

> #coding: utf-8  
> str2 = “asdfÐœÐ¸ÐºÐ¸Ð¼Ð°ÑƒÑ”  
> p str2.encoding #Encoding:UTF-8  
> p str2.scan /\p{Cyrillic}/ #found all cyrillic charachters  
> str2.gsub!(/\w/u,‘’) #removes only latin characters  
> puts str2
> 
> The question is why /\w/ ignore cyrillic characters?
> 
> I have installed latest ruby package from [http://rubyinstaller.org/](http://rubyinstaller.org/).  
> Here is my output of ruby -v  
> ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-mingw32]

[http://redmine.ruby-lang.org/issues/show/3181](http://redmine.ruby-lang.org/issues/show/3181)  
[http://redmine.ruby-lang.org/issues/show/3202](http://redmine.ruby-lang.org/issues/show/3202)

might be related. If you think it’s wrong then bring it up on core.  
-rp

---

<div class="post-metadata">

**Author:** ![karevn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/c68b51/32.png) [@karevn](https://www.ruby-forum.com/u/karevn)\
**Post date:** [May 10, 2010, 7:59pm UTC](https://www.ruby-forum.com/t/win32-ruby1-9-regexp-and-cyrillic-string/187668/4 "2010-05-10T19:59:59Z")

</div>

Caleb C. wrote:

> On 4/27/10, Nikolay K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > #coding: utf-8  
> > str2 = “asdfÐœÐ¸ÐºÐ¸Ð¼Ð°ÑƒÑ”  
> > p str2.encoding #Encoding:UTF-8  
> > p str2.scan /\p{Cyrillic}/ #found all cyrillic charachters  
> > str2.gsub!(/\w/u,‘’) #removes only latin characters  
> > puts str2
> > 
> > The question is why /\w/ ignore cyrillic characters?
> 
> I think that \w (and similar shortcuts) is supposed to match ascii  
> characters only… thus it’s equivalent to [a-zA-Z].
> 
> Isn’t there some kind of unicode character class you can use?

Actually “asdfÐœÐ¸ÐºÐ¸Ð¼Ð°ÑƒÑ”.gsub!(/\w/u,‘’) returns “” on linux so the  
problem is from the windows package.

you can use “asdfÐœÐ¸ÐºÐ¸Ð¼Ð°ÑƒÑ”.gsub!(/\p{L}/,‘’) to remove letters thought

---

<div class="post-metadata">

**Author:** ![karevn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/c68b51/32.png) [@karevn](https://www.ruby-forum.com/u/karevn)\
**Post date:** [May 10, 2010, 8:01pm UTC](https://www.ruby-forum.com/t/win32-ruby1-9-regexp-and-cyrillic-string/187668/5 "2010-05-10T20:01:41Z")

</div>

> Actually “asdfÐœÐ¸ÐºÐ¸Ð¼Ð°ÑƒÑ”.gsub!(/\w/u,’’) returns “” on linux so the  
> problem is from the windows package.
> 
> you can use “asdfÐœÐ¸ÐºÐ¸Ð¼Ð°ÑƒÑ”.gsub!(/\p{L}/,’’) to remove letters thought

If they’re the same version then it might be a window bug. Try it with  
trunk and if it still fails then submit a bug report to the tracker…

---

<div class="post-metadata">

**Author:** ![karevn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/c68b51/32.png) [@karevn](https://www.ruby-forum.com/u/karevn)\
**Post date:** [April 28, 2010, 4:21pm UTC](https://www.ruby-forum.com/t/win32-ruby1-9-regexp-and-cyrillic-string/187668/6 "2010-04-28T16:21:33Z")

</div>

On 4/27/10, Nikolay K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> #coding: utf-8  
> str2 = “asdfÐœÐ¸ÐºÐ¸Ð¼Ð°ÑƒÑ”  
> p str2.encoding #Encoding:UTF-8  
> p str2.scan /\p{Cyrillic}/ #found all cyrillic charachters  
> str2.gsub!(/\w/u,‘’) #removes only latin characters  
> puts str2
> 
> The question is why /\w/ ignore cyrillic characters?

I think that \w (and similar shortcuts) is supposed to match ascii  
characters only… thus it’s equivalent to [a-zA-Z].

Isn’t there some kind of unicode character class you can use?

---

<div class="post-metadata">

**Author:** ![karevn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/c68b51/32.png) [@karevn](https://www.ruby-forum.com/u/karevn)\
**Post date:** [May 10, 2010, 8:33pm UTC](https://www.ruby-forum.com/t/win32-ruby1-9-regexp-and-cyrillic-string/187668/7 "2010-05-10T20:33:28Z")

</div>

Roger P. wrote:

> > Actually “asdfÐœÐ¸ÐºÐ¸Ð¼Ð°ÑƒÑ”.gsub!(/\w/u,‘’) returns “” on linux so the  
> > problem is from the windows package.

Here’s a copy of trunk if that would be useful:

[http://rubydoc.ruby-forum.com/ruby\_distros/ruby\_trunk\_no\_patches\_installed.7z](http://rubydoc.ruby-forum.com/ruby_distros/ruby_trunk_no_patches_installed.7z)

GL.  
-rp
