From: "list. rb" Date: 2007-05-16T18:31:39+09:00 Subject: Re: how to determine if a string is printable? ------=_Part_13060_8082649.1179307899035 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline probably not exactly what you're looking for but I use this quite often for white space removal: " a".strip.empty? On 5/16/07, Michael W. Ryder <_mwryder@worldnet.att.net> wrote: > > Bill Kelly wrote: > > From: "Michael W. Ryder" <_mwryder@worldnet.att.net> > >> Bill Kelly wrote: > >>> > >>> Based on: > >>> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/248540 > >>> > >>> To test for non-printable characters, use: > >>> > >>> str =~ /[^[:print:]]/ > >>> > >> Even though I am not the OP I tried that and using index but none of > >> them seem to work. I get an error message saying "warning character > >> class has '[' without escape" followed by "warning regexp has ']' > >> without escape" and the return is nil regardless what is in the string. > >> Is there something I am missing here? > > > > Not sure. It works for me, without warnings even with ruby -w on: > > ruby 1.8.4 (2005-12-24) [i386-mswin32] > > > > And in IRB: > > > > irb(main):117:0> "abc\ndef" =~ /[^[:print:]]/ > > => 3 # yes, a non-printable character was found at idx 3 > > > > irb(main):118:0> "abcdef" =~ /[^[:print:]]/ > > => nil # no, a non-printable character was not found > > > > > > OK, I see what I did. I forgot the trailing colon. Still getting used > to the language and regular expressions. > > > Regards, > > > > Bill > > > > > > > > ------=_Part_13060_8082649.1179307899035--