Hi, I have a specific set of character ranges which I would like to preserve, and I would like to eliminate all other characters. Normally something like:

$_ =~ s/[^a-z]//g;
Would get rid of anything other than the lower case alphabet. However, this doesn't seem to be working right with my set of character ranges, and I don't know why... I tried the code below and a couple of other variations but I can't get the inversion to work. I can successfully delete all characters in the ranges, I just can't invert the set properly... and I can't explicitly set the ranges I want to delete. any help will be greatly appreciated!
my $shiftjis = q{ [\x30-\x39] | [\x41-\x59] | [\x61-\x7A] | [\x82-\x83][\x3F-\xFE] | [\x88][\x9E-\xFE] | [\x89-\xE9][\x3F-\xFE] | [\xEA][\x3F-\x9F] }; while(<STDIN>){ chomp(); s/[^${shiftjis}]/ogx; print $_."\n"; }

Note: the above doesn't break, it just doesn't do what I'd hoped.

In reply to regex: how to negate a set of character ranges? by kettle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.