From: Jared Richardson Date: 2006-11-20T06:45:06+09:00 Subject: Re: test content string with regex "Luca Scaljery" wrote in message news:30fcaa110523581c1bf28e6b984118ba@ruby-forum.com... > Hi All > > I just tried to test the content of a string, something like this: > > > c = "1234AA" > > if c.scan( /1234567890/ ) > p "OK" > else > p "NO" > end > > > This always returns "OK" :( > > Any suggestions what goes wrong here. And is this the way to check the > content of a string ? > > Thanks a lot > LuCa > > -- because of this irb(main):008:0> a=c.scan( /1234567890/ ) => [] c.scan is returning an empty array, not nil, so your 'if' statement passes. I prefer to do a regex for what you seem to be trying to do. if (c =~(/1234567890/ )) then or if((index=c=~/23211/)) then =~ returns nil for no match. Otherwise you get the index of the content. Jared http://jaredrichardson.net