Well, I'm not sure what you mean by "anything upto a tilda", but you can 
write 1 regex to do what you want:

$ more test.pl
#!/usr/bin/perl
 
$line = '(^FLJK asdf435jk~@!#$';
print "LINE (before): $line\n";
$line =~ s/[^\w\s~]//g;
print "LINE (after): $line\n";

$ perl test.pl
LINE (before): (^FLJK asdf435jk~@!#$
LINE (after): FLJK asdf435jk~

(notice it took out the (^@!#$ characters)

Basically, the s/// is saying to substitute any character matches within 
$line that DON'T (that's the ^) match \w (alphanumeric characters), \s 
(spaces, tabs, newlines) and the ~ (tilda).  If you wanted to avoid other 
characters to substitute, you'd add them here, too.  The second part of the 
s/// says to replace it with nothing and the 'g' at the end says to apply the 
substitution globally over all of $line.

Cheers,

Jason

If memory serves me right, on Wednesday 06 March 2002 06:43, Geoff Ellis 
wrote:
> Could someone let me know how I take out any non printable characters from
> a string, i.e. anything except a-z, 0-9, space, and I think anything upto a
> tilda , if it's possible in 1 regex it would be great..
>
> thanks
>
> Geoff
>
>
> _______________________________________________
> Perl-Unix-Users mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to