<p>I am trying to grab the capital letters of a couple of words and wrap them in span tags. I am using <a href="http://php.net/manual/en/function.preg-replace.php" rel="noreferrer">preg_replace</a> for extract and wrapping purposes, but it's not outputting anything.</p>

<pre><code>preg_replace("/[A-Z]/", "&lt;span class=\"initial\"&gt;$1&lt;/span&gt;", $str)
</code></pre>

[{'answer_id': 1749, 'author': 'Polsonby', 'author_id': 137, 'author_profile': 'https://Stackoverflow.com/users/137', 'pm_score': 7, 'selected': True, 'text': '<p>You need to put the pattern in parentheses <code>/([A-Z])/</code>, like this:</p>\n\n<pre><code>preg_replace("/([A-Z])/", "&lt;span class=\\"initial\\"&gt;$1&lt;/span&gt;", $str)\n</code></pre>\n'}, {'answer_id': 1803, 'author': 'Wedge', 'author_id': 332, 'author_profile': 'https://Stackoverflow.com/users/332', 'pm_score': 3, 'selected': False, 'text': '<p>From the <a href="http://us.php.net/manual/en/function.preg-replace.php" rel="noreferrer">preg_replace documentation</a> on php.net:</p>\n\n<blockquote>\n  <p><em>replacement</em>  may contain references of\n  the form \\n or (since PHP 4.0.4) $n,\n  with the latter form being the\n  preferred one. Every such reference\n  will be replaced by the text captured\n  by the n\'th parenthesized pattern.</p>\n</blockquote>\n\n<p>See Flubba\'s example.</p>\n'}, {'answer_id': 31874, 'author': 'John Douthat', 'author_id': 2774, 'author_profile': 'https://Stackoverflow.com/users/2774', 'pm_score': 5, 'selected': False, 'text': '<p><code>\\0</code> will also match the entire matched expression without doing an explicit capture using parenthesis.</p>\n\n<pre><code>preg_replace("/[A-Z]/", "&lt;span class=\\"initial\\"&gt;\\\\0&lt;/span&gt;", $str)\n</code></pre>\n\n<p>As always, you can go to <a href="http://php.net/preg_replace" rel="noreferrer">php.net/preg_replace</a> or php.net/&lt;whatever search term&gt; to search the documentation quickly. Quoth the documentation:</p>\n\n<blockquote>\n  <p>\\0 or $0 refers to the text matched by the whole pattern. </p>\n</blockquote>\n'}, {'answer_id': 1034121, 'author': 'Dinah', 'author_id': 356, 'author_profile': 'https://Stackoverflow.com/users/356', 'pm_score': 3, 'selected': False, 'text': '<p>Use parentheses around your desired capture.</p>\n'}]
['https://Stackoverflow.com/questions/1746', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/137/']