# Win32 ruby1.9 regexp and cyrillic string

**URL:** <https://rubytalk.org/t/win32-ruby1-9-regexp-and-cyrillic-string/58309>\
**Category:** ruby-talk\
**Created:** [27 April 2010 14:29 UTC](https://rubytalk.org/t/win32-ruby1-9-regexp-and-cyrillic-string/58309 "2010-04-27T14:29:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikolay\_Khodyunya](https://avatars.discourse-cdn.com/v4/letter/n/7c8e57/32.png) [@Nikolay\_Khodyunya](https://rubytalk.org/u/Nikolay_Khodyunya)\
**Post date:** [27 April 2010 14:29 UTC](https://rubytalk.org/t/win32-ruby1-9-regexp-and-cyrillic-string/58309/1 "2010-04-27T14:29:17Z")

</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]

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Roger\_Pack4](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Roger\_Pack4](https://rubytalk.org/u/Roger_Pack4)\
**Post date:** [27 April 2010 16:55 UTC](https://rubytalk.org/t/win32-ruby1-9-regexp-and-cyrillic-string/58309/2 "2010-04-27T16:55:24Z")

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

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Roger\_Pack4](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Roger\_Pack4](https://rubytalk.org/u/Roger_Pack4)\
**Post date:** [27 April 2010 17:20 UTC](https://rubytalk.org/t/win32-ruby1-9-regexp-and-cyrillic-string/58309/3 "2010-04-27T17:20:35Z")

</div>

Nikolay Khodyunya 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/%5C).  
> 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

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Caleb\_Clausen1](https://avatars.discourse-cdn.com/v4/letter/c/8dc957/32.png) [@Caleb\_Clausen1](https://rubytalk.org/u/Caleb_Clausen1)\
**Post date:** [28 April 2010 14:20 UTC](https://rubytalk.org/t/win32-ruby1-9-regexp-and-cyrillic-string/58309/4 "2010-04-28T14:20:47Z")

</div>

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?

> **···**
>
> On 4/27/10, Nikolay Khodyunya \<nickolayho@gmail.com\> 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?

---

<div class="post-metadata">

**Author:** ![Dominic\_Rose](https://avatars.discourse-cdn.com/v4/letter/d/a3d4f5/32.png) [@Dominic\_Rose](https://rubytalk.org/u/Dominic_Rose)\
**Post date:** [10 May 2010 18:00 UTC](https://rubytalk.org/t/win32-ruby1-9-regexp-and-cyrillic-string/58309/5 "2010-05-10T18:00:00Z")

</div>

Caleb Clausen wrote:

> **···**
>
> > On 4/27/10, Nikolay Khodyunya \<nickolayho@gmail.com\> 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  
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Roger\_Pack4](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Roger\_Pack4](https://rubytalk.org/u/Roger_Pack4)\
**Post date:** [10 May 2010 18:01 UTC](https://rubytalk.org/t/win32-ruby1-9-regexp-and-cyrillic-string/58309/6 "2010-05-10T18:01:43Z")

</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...

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Roger\_Pack4](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Roger\_Pack4](https://rubytalk.org/u/Roger_Pack4)\
**Post date:** [10 May 2010 18:33 UTC](https://rubytalk.org/t/win32-ruby1-9-regexp-and-cyrillic-string/58309/7 "2010-05-10T18:33:30Z")

</div>

Roger Pack 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

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
