From: William James Date: 2008-09-17T17:32:38+09:00 Subject: Re: Problem with getting RegEx to work On Sep 17, 3:19 am, henrik...@gmail.com wrote: > All, > > I'm a novice when it comes to Ruby so I'm hoping that one of you guys > can explain the following to me. > > The following line works as I expected it to and prints "This is a > test" with one word per line: > " -XThis -Xis -Xa -Xtest ".scan( /-X(.*?)\s/ ) { |x| puts x } > > However this line only prints 4 lines of empty text: > " -XThis -Xis -Xa -Xtest ".scan( /\s-X(.*?)/ ) { |x| puts x } > > Can someone explain this to me? > Thanks. * means zero or more, so Ruby gives you zero characters. " -XThis -Xis -Xa -Xtest ".scan( /\s-X(\S*)/ ) ==>[["This"], ["is"], ["a"], ["test"]]