in reply to Re: Match any characters
in thread Match any characters

Thanks. I've just discovered a slight variation on the theme in the log I'm interrogating which will need handling however.
It seems that the first element after logger is not always a password. This field may be alphanumeric and possibly include the @ # Ł $ and _ characters (but no others) and may not be surrounded by quotes e.g.
logger abc@def,"werty^%$&" logger ab$Łef,12trsgh logger "765)(?>jh",hhhhhh,joebloggs logger "7,)(?>jh",yyyyyyy,fredbloggs
Where the output should be
logger abc@def,XXXXXXXXX logger ab$Łef,XXXXXXX logger XXXXXXXXXXX,XXXXXX,joebloggs logger XXXXXXXXXX,XXXXXXX,fredbloggs
How do I adapt the code to handle that ?

Replies are listed 'Best First'.
Re^3: Match any characters
by GrandFather (Saint) on Feb 10, 2006 at 11:19 UTC

    Cleaner to do that with a number of matches:

    use warnings; use strict; use Data::Dumper; while (<DATA>) { if (/logger\s+"([^"]*)",(\w+),(.*)/s) { print "logger " . ('X' x length $1) . ',' . ('X' x length $2) +. ",$3"; } elsif (/logger\s+([^,]*),"([^"]*)"(,?.*)/s) { print "logger $1," . ('X' x length $2) . "$3"; } elsif (/logger\s+([^,]*),(\w+)(,?.*)/s) { print "logger $1," . ('X' x length $2) . "$3"; } } __DATA__ logger abc@def,"werty^%$&" logger ab$Łef,12trsgh logger "765)(?>jh",hhhhhh,joebloggs logger "7,)(?>jh",yyyyyyy,fredbloggs

    Prints:

    logger abc@def,XXXXXXXXX logger ab$Łef,XXXXXXX logger XXXXXXXXX,XXXXXX,joebloggs logger XXXXXXXX,XXXXXXX,fredbloggs

    DWIM is Perl's answer to Gödel
      Many thanks