From: Mike Stok Date: 2002-10-03T05:43:49+09:00 Subject: Re: Regexp: Stripping out all except ASCII? In article <5.1.0.14.2.20021002161707.030aecd8@zcard04k.ca.nortel.com>, Mark Probert wrote: > > Hi. > > A simple one, again. How do I strip out all chars > except valid ASCII from a file? > > while line = gets() > line.sub(/[^\w]/, " ") > puts line > end > > leaves stuff, such as ESC sequences. Any ideas? > Is there a one-liner for this? Did you mean to say line.gsub!(/\W/, ' ') which will change all non-word characters in line to spaces and modifies line? What do you mean by "valid ASCII" here? Are you really after printable characters < chr(128)? e.g. line.gsub!(/[^ -~]/, ' ') Hope this helps, Mike -- mike@stok.co.uk | The "`Stok' disclaimers" apply. http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60 http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA