I would like to hide the last two sections from an IP address using regular expression the problem is that the asterix (*
) must match the length of those sections.
Eg: 10.101.12.100
should be re-formated into 10.101.**.***
This is the code I'm working with :
echo preg_replace('!(\d+).(\d+).\d+.\d+!s', '${1}.${2}.***.***', "10.101.12.100");
// Return: 10.101.***.***
Is that possible using regex ?
PS: I know I could break it using explode('.', ...)
along with str_repeat('*', strlen(...))
but I find preg_replace
a cleaner solution. I'm looking for a "oneliner" solution.