powerhouse has asked for the wisdom of the Perl Monks concerning the following question:

I cannot remember how to do this... I'm trying to "strip" certain characters out of a variable. Such as æ or Æ or even just A-Z how do I do it?

$string =~ s/[A-Za-z]//;
I'm embarassed that I cannot remember this.

I guess If I go to bed, when I wake up I might remember. I cannot thing straight. Can someone please refresh my memory.
thx,
Richard

Replies are listed 'Best First'.
Re: Stripping characters...
by fruiture (Curate) on Mar 04, 2003 at 08:44 UTC

    To create a complementary character class, use [^...], see perlre. In order to strip characters, tr/// is the better (=more efficient) choice:

    $string =~ tr/a-zA-Z//cd;

    See perlop for what tr///cd does.

    --
    http://fruiture.de
Re: Stripping characters...
by hotshot (Prior) on Mar 04, 2003 at 09:09 UTC
    you can also use:
    $string =~ s/[A-Za-z]//g;
    you just need to add 'g' at the end of your regexp.

    Hotshot