Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Cleaning the Log

by demerphq (Chancellor)
on Sep 02, 2002 at 15:55 UTC ( [id://194601]=note: print w/replies, xml ) Need Help??


in reply to Cleaning the Log

Actually this is more complicated than a pure regex can handle (perl regexes _may_ be able to handle this, but the code would be scaaaary), this problem is even more difficult than handling balanced constructs and cannot be solved using a formal regular expression.

This is because we cant simply look for .{BS}, as is clear from your sample data such as bnack{BS}{BS}{BS}{BS} where the last {BS} actually remove the 'n'.

But only a slight amount of additional code will allow a working solution....

my $logdata=<<EOLOG; pass{BS}{BS}{BS}{BS}{BS}{BS} hee{BS}llo, I'll be bnack{BS}{BS}{BS}{BS}ack next saturday.{BS}{BS}{BS +}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS}{BS} www.yahoo.com "keyloggers" + "linux"{BS}{BS}{BS} EOLOG my $clean; while ($logdata=~/\G(\{BS}|.)/sg) { length ($1)>1 && (length($clean)==0 || substr($clean,length($clean +)-1,1,"")) or $clean.=$1; } print $clean;
YMMV

Yves / DeMerphq
---
Software Engineering is Programming when you can't. -- E. W. Dijkstra (RIP)

Replies are listed 'Best First'.
Re^2: Scaring the Log
by Aristotle (Chancellor) on Sep 03, 2002 at 14:34 UTC
    perl regexes _may_ be able to handle this, but the code would be scaaaary
    I felt like doing something scary. *grin* The trick is to use sexeger - a regex that operates on the reversed string.
    s/{BS}/\b/g; $_ = reverse $_; my $k = 0; s/(\010+)(??{ $k += length $+; "([^\010]{0,$k})" })(?{ $k -= length $+ + })//g; $_ = reverse $_;
    Don't forget to tune in for the next issue of H.R. Giger meets Perl. *grin*

    Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://194601]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2025-03-24 19:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (65 votes). Check out past polls.

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.