in reply to Re: regex question
in thread regex question

$string =~ tr/A-Za-z0-9.-_//cd;
You forgot to escape the hyphen, the one you want taken literally:
$string =~ tr/A-Za-z0-9.\-_//cd;

Yours will keep everything in the range

./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
too, which is more than you wanted.

Replies are listed 'Best First'.
Re^3: regex question
by davido (Cardinal) on Dec 06, 2006 at 07:25 UTC

    What I should have said (and intended to but didn't) is:

    tr/A-Za-z0-9._-//cd;

    The hyphen doesn't have special meaning in that case. I even did that when I composed the character class demonstrated in my s/// example, but somehow missed it in the tr/// example.

    Good catch bart. :) You've got to love Perl's density huh? ;)


    Dave