From: John Carter Date: 2008-01-14T09:56:55+09:00 Subject: Re: regex help partial code On Mon, 14 Jan 2008, Junkone wrote: > irb(main):046:0> a=Regexp.new('(add)\s+(\S+)\s+([i|s|f])\s+([pei])?\s > +',true) > => /(add)\s+(\S+)\s+([i|s|f])\s+([pei])?\s+/i > irb(main):047:0> a =~("Add comp i pe") > => nil > > I dont get match at 4th token irb irb(main):002:0> /(add)\s+(\S+)\s+([i|s|f])\s+([pei])?\s+/i =~ "Add comp i pe" => nil irb(main):003:0> /(add)\s+(\S+)\s+([i|s|f])\s+([pei])?/i =~ "Add comp i pe" => 0 The last \s+ insists on matching one or more whitespace chars. Here is a general recipe for solving this class of problems.... Set up a simple test like I have above... Delete elements out of the regex until it matches. The problem was the last one you deleted. John Carter Phone : (64)(3) 358 6639 Tait Electronics Fax : (64)(3) 359 4632 PO Box 1645 Christchurch Email : john.carter@tait.co.nz New Zealand