On Mon, 18 Nov 2002, Beau E. Cox wrote: > Hi - > > This will 'strip' all but a-zA-Z0-9: > > #!/usr/bin/perl > > use strict; > use warnings; > > my $STRING = "kjsh234Sd\nki"; > > $STRING =~ s/[^a-zA-Z0-9]//sg; > > print "$STRING\n"; > > the ~ makes the character class negative,
I guess you meant ^, not ~ > the s makes > the regex examine new lines, and g means global. You need an /s when you want . to match newlines (which it normally doesn't). In this case since you are not using a .., /s is not needed. $STRING =~ s/[^a-zA-Z0-9]//g; The above will work just fine You can also use tr/// for this $STRING =~ tr/a-zA-Z0-9//cd; If the OP just wants to check not replace either of these should do unless ($STRING =~ m/[^a-zA-Z0-9]/) { # Valid STRING } or unless ($STRING =~ tr/a-zA-Z0-9//c) { # Valid STRING } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]