From: Stefan Lang Date: 2008-03-08T09:41:28+09:00 Subject: Re: Bug in regex engine ?? Must be... 2008/3/3, D. Krmpotic : > Hi, > > I'm using Ruby 1.8.6, and I just discovered something rather > interesting, here is a test: > > require 'test/unit' > > class TestRegexBug < Test::Unit::TestCase > > def test_bug > > hours = "pon-èet" > > assert(hours =~ /[è]et/i) > assert(hours =~ /èet/i) > assert(hours =~ /-èet/i) > assert(hours =~ /[cè]et/i) > assert(hours =~ /-[è]et/i) > > end > > end > > As you can see, this only happens with unicode letters... (the last test > fails).. I'm used to the fact that //i doesn't work for unicode chars > and I already know that you need two dots to match one of these.. But > this problem is different and weirder, because what triggers it is a > minus sign before the square brackets.. if you remove either the '-' or > '[]' from the regex, it works.. In the regex [è] is a character class with _two_ bytes. So Ruby tries to match a minus followed by _one_ of the bytes out of "è" followed by "et". So the regex would match "pon-\304et" or "pon-\215et", but not "pon-\304\215et". Stefan