Note that this set of regexes will convert '&lt;' to '<' due to the repeated substitutions. But you could do the & substitution last to avoid that. Percents are also documented as something that gets escaped, so you'll want a substitution for that too.