[Fwd: SPUG:regex question]

Islandman schieb at centurytel.net
Tue Jan 28 14:54:14 CST 2003


"Michael R. Wolf" wrote:


$printable =~ s#[[:^print:]]##g;  <--- that's it!! thanks Michael!

-Brian




> 
> Islandman <schieb at centurytel.net> writes:
> 
> > Will try again. Expected I was the only one who did not know the regex
> > for removing all non-printable characters from a text string, but
> > haven't got the answer just yet.
> >
> > Super-spiffy regex to accomplish this would be most appreciated.
> 
> I tried to use a \p{IsPrint}, but didn't get it to work.  The [:print]
> POSIX character works as below.
> 
> #! /usr/bin/perl -w
> 
> my $all;
> $all .= $_ for map {chr($_)} 0..1024;
> 
> if (open CATV, "| cat -vet") {
>     printf CATV "Everything(%d chars), printed visably\n", length($all);
>     print CATV $all;
>     close CATV;
> } else {
>     warn "can't open cat for visable printing: $!";
> }
> 
> # Remove the non-printables.  See pg 175 of "Programming Perl" 3rd
> # edition for character classes.
> my $printable = $all;
> $printable =~ s#[[:^print:]]##g;
> 
> print "\n" x 3, "=" x 78, "\n";
> printf "Only the printables (%d chars):\n", length($printable);
> print "V" x length($printable), "\n";
> print $printable, "\n";
> print "^" x length($printable), "\n";
> 
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
> POST TO: spug-list at mail.pm.org
> ACCOUNT CONFIG: http://mail.pm.org/mailman/listinfo/spug-list
> MEETINGS: 3rd Tuesdays, U-District, Seattle WA
> WEB PAGE: www.seattleperl.org



More information about the spug-list mailing list