Pattern matching on ampersands and other characters doesn't check for the context of where they appear. For instance, an ampersand in a title attribute of an anchor tag inserts <span class="amp"> which gives you a lot of double quotes and breaks the HTML. Really, the regex should check and make sure it's not doing a replacement inside HTML, or at least in certain contexts.