I have a string of HTML. Inside it are "magic words," which I need to replace as links, using C#. This is a string replace operation, not a DOM parse. So...

```
This is a magic word.

```

...needs to become...

```
This is a <a href="/link.html">magic</a> word.

```

It's a fairly easy replace operation, except, what do I do if the word is already linked in the input. So if this is my input:

```
This is a <a href="/link.html">magic</a> word.

```

I end up with this:

```
This is a <a href="/link.html"><a href="/link.html">magic</a></a> word.

```

That might be easy to get around, by searching for whitespace or brackets or something, but what about this:

```
This is a <a href="/link.html">crazy magic stuff</a> word.

```

The string " magic " is free-floating there in the middle, and I'll get this:

```
This is a <a href="/link.html">crazy <a href="/link.html">magic</a> stuff</a> word

```

What would be the right way to approach this?