Hi, I have a problem in specifying a pattern match where the string can include anything. I'm tring to hide passwords in text. The basic formats of the text are as follows.
Format 1
logger abcdef123,"$£*&GHi^
Note that both of the elements delimited by the comma are passwords. If a password contains non alphanumeric characters it has to be in quotes.
Format 2
logger "765)(?>jh",hhhhhh,joebloggs
In this example I would only want to hide elements 1 & 2. The third is a username.
The code I was using which worked until the passwords were changed to include non-alphanumeric characters was
$string =~ s/(logger\s+)(\w+)(\W+)(\w+)/$1 . ("X" x length($2) . $3 .
+("X" x length($4))/e;
A caveat is that if a password is inside quotes it may actually contain a comma as part of the password !
How do I change this to be able to handle any characters in the password ?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.