Selectively replacing words outside of tags using regular expressions in PHP? <p>I have a paragraph of text and i want to replace some words using PHP (preg_replace). Here's a sample piece of text:</p> <p><code>This lesson addresses rhyming [one]words and ways[/one] that students may learn to identify these words. Topics include learning that rhyming words sound alike and these sounds all come from the [two]ending of the words[/two]. This can be accomplished by having students repeat sets of rhyming words so that they can say them and hear them. The students will also participate in a variety of rhyming word activities. In order to demonstrate mastery the students will listen to [three]sets of words[/three] and tell the teacher if the words rhyme or not.</code></p> <p>If you notice there are many occurances of the word 'words'. I want to replace all the occurances that <strong>don't</strong> occur inside any of the tags with the word 'birds'. So it looks like this:</p> <p><code>This lesson addresses rhyming [one]words and ways[/one] that students may learn to identify these birds. Topics include learning that rhyming birds sound alike and these sounds all come from the [two]ending of the words[/two]. This can be accomplished by having students repeat sets of rhyming birds so that they can say them and hear them. The students will also participate in a variety of rhyming word activities. In order to demonstrate mastery the students will listen to [three]sets of words[/three] and tell the teacher if the birds rhyme or not.</code></p> <p>Would you use regular expressions to accomplish this?<br> <em>Can</em> a regular expression accomplish this?</p>