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

I want to keep the "/" character from being filtered out. How do I put it in the "[^]" section:
#!/usr/bin/perl -w use strict; my $code = "xx;1:{}/x %"; # I want to keep "/" from being filtered out $code =~ s/[^\w"':.;]//g; print $code;

Replies are listed 'Best First'.
Re: RegEx Character Class
by moritz (Cardinal) on Sep 12, 2007 at 07:26 UTC
    You have to add it to the (negated) char class:

    s/[^\w"':.;\/]//g;

    or s{[^\w"':.;/]}{}g;

Re: RegEx Character Class
by atemon (Chaplain) on Sep 12, 2007 at 07:29 UTC

    To keep "/", please add "\/"

    $code =~ s/[^\/\w"':.;]//g;
    will keep "/".

    Cheers !

    --VC



    There are three sides to any argument.....
    your side, my side and the right side.

      To keep "/", please add "\/"

      If using alternate delimiters, there's no need to protect '/'.

      $code =~ s/[^\/\w"':.;]//g;

      BTW: this is a perhaps a job better suited for tr///d, except that it doesn't support \w and one would have to hardcode the ranges - and it may even be worse if unicode were involved, but the OP may like to know anyway.