I'm writing a custom HTML mark-up form that will take in text and format it in a specified way. One of the functions is to add <span> tags to certain subheader phrases and words. What I want to do is to be able to highlight the subheader phrase and then use Regex to take the selected text and replace all other instances of it, except for those that already have span tags. For instance:

Subheader phrase

Paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph

Subheader phrase

Paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph

<span class="Title">Subheader phrase</span>
I should be able to highlight "Subheader phrase" with the cursor, run the routine, and get this:

<span class="Title">Subheader phrase</span>

Paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph

<span class="Title">Subheader phrase</span>

Paragraph paragraph paragraph paragraph paragraph paragraph paragraph paragraph

<span class="Title">Subheader phrase</span>
Here's the code so far:

Code:
string input = tbMain.SelectedText;
string output = input;
input = "<span class=\"Title\">" + input + "</span>";
            
Regex rgx = new Regex(output + @"(?!</span>)");
MatchCollection m = Regex.Matches(tbMain.Text, output + @"(?!</span>)");

if (output.Length > 0 && m.Count > 0)
{              
            tbMain.Text = rgx.Replace(tbMain.Text, "<span class=\"Title\">" + output + "</span>");
            lblStatus.Text = "Status: Successfully replaced " + m.Count + " subheadings";
}
else
{
            tbMain.SelectedText = input;
}
For the most part, it seems to be working, but I've found that it replaces partial matches as well. For instance, highlighting "Who" replaces any instance of "W" or "Wh" as well. Any thoughts as to how to fix this? I'm using .NET 4.0. Thanks in advance!