On 22.06.2007 14:15, growlatoe / yahoo.co.uk wrote: >>> It's because the pattern /.*/ matches everything, including the >>> absence of everything. >>> So: since * matches "zero or more" characters when it starts the >>> search for .* it matches the absence (the 'zero') and then matches the >>> string (the 'or more'). >> It's the other way around, though; it matches "hello" *first*, and >> then "". So the zero-matching (which I admit I'm among those who find >> unexpected) is happening at the end. > > Oh right, I think I get it now. If you try to match anything with * > then a match is guaranteed, because if there's nothing to match, then > you'll just match nothing? > > Like this: > > irb(main):001:0> "hello".scan(/h*/) > => ["h", "", "", "", "", ""] > > And this: > > irb(main):002:0> "hello".scan(/P*/) > => ["", "", "", "", "", ""] > > > I've always assumed, and used, .* to make everything before, > but I suppose .+ does make more sense. Although I have to say > I still find it a bit odd... ".*" has its use but it's generally overrated, i.e. more often used than needed / wanted. If you show a more concrete example of what you are doing we might be able to come up with better suggestions. If you are really interested to dive into the matter then I suggest "Mastering Regular Expressions" which is an excellent book for the money. Kind regards robert