I am currently using the following regular expression to replace words in html with links, whilst ignoring html tags. (?!<.*?)(%s)(?![^<>]*?>) Code (markup): Please could someone explain to me what it means? I am trying to modify it so that it does not replace the text between anchor tags. I currently end up getting things like <a href="">this is a <a href="">link</a></a> Code (markup): , which I don't want. Thanks for your help, James.