replace some preg_replace by preg_replace_callback (closes #4125)