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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…