<?php $string = "pub-1885335825402893"; echo preg_replace('~(?:\G(?!^)|^pub-\d{5}(?=\d*$))\K\d(?=\d{5})~', '*', $string);
You have javascript disabled. You will not be able to edit any code.