in reply to stripping everything but numbers and letters
As you have + inside your character class, it will not be replaced.
my $s = 'abc123+'; $s =~ s/[^0-9+]//g;
Maybe you wanted a quantifier, which should be placed directly after the character class.
$s =~ s/[^0-9]+//g;
You can also use tr///:
$s = 'abc123+'; # remove any non-digit $s =~ tr/0-9//cd; # or remove any non-alphanumeric $s =~ tr/A-Za-z0-9//cd;
See perldoc perlop for details (Search for 'tr/SEARCHLIST/REPLACEMENTLIST/cds' ).
Update
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: stripping everything but numbers and letters
by jwkrahn (Abbot) on Feb 06, 2009 at 12:10 UTC | |
by linuxer (Curate) on Feb 06, 2009 at 12:30 UTC | |
|
Re^2: stripping everything but numbers and letters
by cdarke (Prior) on Feb 06, 2009 at 11:42 UTC | |
by linuxer (Curate) on Feb 06, 2009 at 11:53 UTC |