# Unprintable characters

**URL:** <https://www.ruby-forum.com/t/unprintable-characters/173775>\
**Category:** Ruby\
**Created:** [August 14, 2009, 3:46pm UTC](https://www.ruby-forum.com/t/unprintable-characters/173775 "2009-08-14T15:46:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sclarke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sclarke](https://www.ruby-forum.com/u/sclarke)\
**Post date:** [August 14, 2009, 3:46pm UTC](https://www.ruby-forum.com/t/unprintable-characters/173775/1 "2009-08-14T15:46:19Z")

</div>

Hi all,

Rather difficult problem I have I think.

I am processing large amounts of data and at the end of processing I  
wish to remove all unprintable characters from the resulting file.

At the moment I have to load the file up into a good text application  
and run a find and replace find the following phrase

find: [^[:print:]]  
replace:

I then select regular expression of the find and replace and it goes off  
and looks for all unprintable characters and replaced them with nothing.

Ideally I would like to do this in Ruby, something like

data.gsub([^[:print:]], “”)

Obviously it is far more complex that this and I am looking for input.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![sclarke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sclarke](https://www.ruby-forum.com/u/sclarke)\
**Post date:** [August 14, 2009, 5:51pm UTC](https://www.ruby-forum.com/t/unprintable-characters/173775/2 "2009-08-14T17:51:04Z")

</div>

On Aug 14, 9:46 am, Stuart C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> find: [^[:print:]]
> 
> ## Thanks in advance
> 
> Posted viahttp://www.ruby-forum.com/.

is it?

this seems to work without problem for me:

data = File.read(“some/crazy/mp3”)  
data.gsub(/[^[:print:]]/, “”)

Ruby 1.9 needs force\_encoding(“binary”), but basically the same deal.

I assume I’m missing something obvious :\
