From: dblack@... Date: 2006-11-25T10:07:50+09:00 Subject: Re: [QUIZ] DictionaryMatcher (#103) Hi -- On Sat, 25 Nov 2006, Jamie Macey wrote: > On 11/24/06, dblack@wobblini.net wrote: >> What's the ruling on priority and "greediness"? In other words, >> given: >> >> dm << "hi" >> dm << "child" >> >> what would: >> >> dm =~ "children" >> >> give? Would it be different if you added "child" first? Or is there >> a rule about finding the longest match? > > I'm doing the same thing a regexp does. > > In this case, both /hi|child/ =~ 'children' and /child|hi/ =~ > 'children' return 0, so I'm returning the index of the first character > in the string that matches the uber-regexp we're standing in for. Actually, a better example of what I was pondering would be: dm << "t" dm << "ten" dm =~ "tenth" However, I guess as long as it's just the starting offset that's needed, and not the ending offset (i.e., we don't have to know how long the match is), it won't be an issue. My instinct was to want to know which string did the matching, but for starting offset purposes it doesn't matter. David -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org