trying to match non ascii chars
am 17.06.2011 18:01:02 von Chris Knipe
------=_NextPart_000_0048_01CC2D18.876D3D10
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Hi,
I have bit of problem with transparent squid service. When people tries
to send binary data through squid, the log files naturally doesn't like it
very much. A sample of such an log file entry:
1308293915.456 0 client.host.name NONE/400 3660
[<92>i<8F>>^]^D^N<9F>?[y<81>'4/^<92>kI${
b<8B>o^S %87)d%B8%5B%F6W%A2$%5C - NONE/- text/html
I am trying to write perl regex to skip lines containing these characters,
but I'm not having too much success:
while (<>) {
chomp($_);
if ($_ =~ s/[\t\n\r\f\a\e\cK]//g) {
next;
} else {
print $_ . "\n";
}
}
Does anyone perhaps have some insight for me?
Regards,
Chris.
------=_NextPart_000_0048_01CC2D18.876D3D10--
Re: trying to match non ascii chars
am 17.06.2011 19:44:32 von Shawn H Corey
On 11-06-17 12:01 PM, Chris Knipe wrote:
> Does anyone perhaps have some insight for me?
Try:
while( <> ){
next if /[^\000-\177]/;
print;
}
--
Just my 0.00000002 million dollars worth,
Shawn
Confusion is the first step of understanding.
Programming is as much about organization and communication
as it is about coding.
The secret to great software: Fail early & often.
Eliminate software piracy: use only FLOSS.
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: trying to match non ascii chars
am 17.06.2011 19:52:18 von jwkrahn
Chris Knipe wrote:
> Hi,
Hello,
> I have bit of problem with transparent squid service. When people tries
> to send binary data through squid, the log files naturally doesn't like it
> very much. A sample of such an log file entry:
>
> 1308293915.456 0 client.host.name NONE/400 3660
> [<92>i<8F>>^]^D^N<9F>?[y<81>'4/^<92>kI${
> b<8B>o^S %87)d%B8%5B%F6W%A2$%5C - NONE/- text/html
>
> I am trying to write perl regex to skip lines containing these characters,
> but I'm not having too much success:
>
> while (<>) {
> chomp($_);
> if ($_ =~ s/[\t\n\r\f\a\e\cK]//g) {
> next;
> } else {
> print $_ . "\n";
> }
> }
>
> Does anyone perhaps have some insight for me?
while ( <> ) {
chomp;
next if /[^[:ascii:]]/;
print "$_\n";
}
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/