\\1'; $replace[] = '\\1'; $text2 = preg_replace($pattern, $replace, $text); preg_match_all($pattern[1], $text, $matches); echo htmlentities($text) . '' . htmlentities($text2) . '' . print_r($matches, 1); ?>