Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: numbers masking

by salva (Abbot)
on May 16, 2012 at 08:15 UTC ( #970773=note: print w/ replies, xml ) Need Help??


in reply to numbers masking

$number =~ /^(\D*\d){6}/g and $number =~ s/\G(\D*)\d(?=(?:\D*\d){4})/$ +{1}X/g;

or another somewhat less cryptic approach:

my ($s, $m ,$e) = $number =~ /^((?:\D*\d){6})(.*)((?:\d\D*){4})$/; $m =~ tr/0-9/X/; $number = "$s$m$e"

or with a recent perl:

$number =~ s|^((?:\D*\d){6})(.*)(?=(?:\d\D*){4})|$1. ($2 =~ tr/0-9/X/r +)|e;


Comment on Re: numbers masking
Select or Download Code
Replies are listed 'Best First'.
Re^2: numbers masking
by Anonymous Monk on May 16, 2012 at 09:12 UTC

    thnks salva. But can please explain the crytic approach(1st one)

      Well, IMO, the expression is not so complex, but you need to understand how regular expressions can be chained using \G and what look-ahead assertions do. Both things are explained in perlre.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2015-08-31 03:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...













    Results (352 votes), past polls