How can I get at the matches when using preg_replace in PHP?

html-parsing, php, preg-replace, regex

Solution

You need to put the pattern in parentheses `/([A-Z])/`, like this:

preg_replace("/([A-Z])/", "<span class=\"initial\">$1</span>", $str)

Problem

I am trying to grab the capital letters of a couple of words and wrap them in span tags. I am using preg_replace for extract and wrapping purposes, but it's not outputting anything. ``` preg_replace("/[A-Z]/", "<span class=\"initial\">$1</span>", $str) ```

Original source