<p>Say I have the following string:</p>

<pre><code>"I am the most foo h4ck3r ever!!"
</code></pre>

<p>I'm trying to write a makeSpecial(foo) function where the foo substring would be wrapped in a new span element, resulting in:</p>

<pre><code>"I am the most &lt;span class="special"&gt;foo&gt;&lt;/span&gt; h4ck3r ever!!"
</code></pre>

<p>BeautifulSoup seemed like the way to go, but I haven't been able to make it work.</p>

<p>I could also pass this to the browser and do it with javascript, but that doesn't seem like a great idea.</p>

<p>Some advice for this would be really useful, especially in python. </p>

How about this:
```
```
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def makeSpecial(mystring, special_substr):
...     return mystring.replace(special_substr, '<span class="special">%s</span>
' % special_substr)
...
>>> makeSpecial("I am the most foo h4ck3r ever!!", "foo")
'I am the most <span class="special">foo</span> h4ck3r ever!!'
>>>
```
```