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)\Kis used to find an entry point for the chain:
\ba word boundary (zero-width) and matching\d{4}four digits
(?=\d{12}\bif followed by 12 digits -\Kresets the reported match.|\G\Bthe right side of the alternation is to\Gchain matches at\B
which is a non word boundary to prevent\Gfrom matching at start.
This will only work, if \G and \K are supported in Splunk's replace-function.
