<clippy>It looks like you are trying to build a negated character class. Would you like some help?</clippy>
You have the syntax for including several ranges within a character class wrong. Simple rule: Within a character class, [, |, and whitespace (even with /x) are literal, and ] terminates the class (except in first position). So keep those square braces out until constructing the class, and keep the pipes and whitespace out, period.
Ah, but then, clippy may have been wrong? What you are trying to do is combine (and then negate) multi-character sequences, right?
Oh my. Combining is easy. What you have even works, though I'd personally use qr//x instead:
my $shiftjis = qr{ [\x30-\x39] | [\x41-\x59] | [\x61-\x7A] | [\x82-\x83][\x3F-\xFE] | [\x88][\x9E-\xFE] | [\x89-\xE9][\x3F-\xFE] | [\xEA][\x3F-\x9F] }x;
Negating is another subject alltogether, since there is more than one set of semantics for such a negation. I'm not entirely sure which makes more sense here ... if any! Here's one example/guess though:
while(<STDIN>){ chomp(); # Oops, nope -- variable-length lookbehind: # s/(?!$shiftjis).(?<!$shiftjis)//ogx; # This runs, but doesn't do the job: # s/(?!$shiftjis).//ogx; # This should work: s/(?!$shiftjis). (?<![\x30-\x39\x41-\x59\x61-\x7A]) (?<![\x82-\x83][\x3F-\xFE] |[\x88][\x9E-\xFE] |[\x89-\xE9][\x3F-\xFE] |[\xEA][\x3F-\x9F]) //ogx; print $_."\n"; }
But do you have to read STDIN as bytes? If you could read it as characters (in whatever encoding this is; see Encode), you'd be spared this mess.
print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!
In reply to Re: regex: how to negate a set of character ranges?
by Sidhekin
in thread regex: how to negate a set of character ranges?
by kettle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |