Home > front end >  Mask 8 Integers in the middle of a 16 length integer with * (Credit Card numbers)
Mask 8 Integers in the middle of a 16 length integer with * (Credit Card numbers)

Time:07-13

I need to extract and mask the middle 8 integers from a 16 digit number and mask them.


E.g.:

1759759473504563

End result:

1759********4563

In case it helps in any way I need it to help mask credit card numbers in Splunk.

CodePudding user response:

Looks like Splunk uses PCRE Regex. Have a try with

(?:\b\d{4}(?=\d{12}\b)\K|\G\B)\d(?=\d{4})

and use * or whatever you like as replacement - See this regex101 demo.

The idea is to use the \G anchor for chaining matches and \K to reset.

  • \b\d{4}(?=\d{12}\b)\K is used to find an entry point for the chain:
    \b a word boundary (zero-width) and matching \d{4} four digits
    (?=\d{12}\b if followed by 12 digits - \K resets the reported match.
  • |\G\B the right side of the alternation is to \G chain matches at \B
    which is a non word boundary to prevent \G from matching at start.

This will only work, if \G and \K are supported in Splunk's replace-function.

  • Related