fix preg_replace and add some tests