Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Regex to convert non-printable to printable char

by GlitchMr (Sexton)
on Aug 22, 2012 at 10:04 UTC ( #989002=note: print w/ replies, xml ) Need Help??


in reply to Regex to convert non-printable to printable char

Just a note, \x7F is also unprintable character, In one of my scripts, I use following translation to filter non-printable characters.

tr[\0-\x1F\x7F] [\x{2400}-\x{241F}\x{2421}]

\x{2420} is space, in case you have noticed a gap in range. If you don't want to replace them with Unicode non-printable graphics characters, you could replace \x{2400}-\x{241F}\x{2421} with ? or \x{FFFD} (Unicode replacement character).

Also, in most cases you wouldn't want to match \x09 (tab), \x0A (line feed) or \x0D (carriage return). You could use this translation when you don't want to match them.

tr[\0-\x08\x0B\x0C\x0E-\x1F\x7F] [\x{2400}-\x{2408}\x{240B}\x{240C}\x{240E}-\x{241F}\x{2421}]

It also doesn't work on EBCDIC, if you want to match EBCDIC, most likely you will need different range of characters (\x00-\x3F\xFF).


Comment on Re: Regex to convert non-printable to printable char
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://989002]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2014-09-21 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (166 votes), past polls