From: Shai Rosenfeld Date: 2006-11-20T17:19:23+09:00 Subject: Re: test content string with regex Luca Scaljery wrote: > 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 (i think) the reason you always get OK, is because the if c.scan always returns a true value (the scan method always takes place) (i.e, it never returns nil/false)...i don't know exactly what method you need, but first of all check out http://rubycentral.com/book/ref_c_string.html#String.scan to see that it returns either an array or a string, and second of all maybe, check out, Regexp#=~ , maybe that is better? hth, harp -- Posted via http://www.ruby-forum.com/.