Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Removing Non-Ascii chars from text file

by rsriram (Hermit)
on Jun 07, 2007 at 12:36 UTC ( #619797=note: print w/replies, xml ) Need Help??


in reply to Removing Non-Ascii chars from text file

Try this,

$str =~ s/[^!-~\s]//g;

In the above, !-~ is a range which matches all characters between ! and ~. The range is set between ! and ~ because these are the first and last characters in the ASCII table (Alt+033 for ! and Alt+126 for ~ in Windows). As this range does not include whitespace, \s is separately included. \t simply represents a tab character. \s is similar to \t but the metacharacter \s is a shorthand for a whole character class that matches any whitespace character. This includes space, tab, newline and carriage return.

Or simply, $str !~ s/[^[:ascii:]]//g;

Replies are listed 'Best First'.
Re^2: Removing Non-Ascii chars from text file
by Anonymous Monk on Oct 27, 2011 at 06:25 UTC
    Cool. This worked for me. Thanks.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2019-07-22 11:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?






    Results (15 votes). Check out past polls.

    Notices?