# pre\_replace not sure what the correct expression is

**URL:** <https://forum.kirupa.com/t/pre-replace-not-sure-what-the-correct-expression-is/296816>\
**Category:** programming\
**Created:** [September 21, 2009, 12:05pm UTC](https://forum.kirupa.com/t/pre-replace-not-sure-what-the-correct-expression-is/296816 "2009-09-21T12:05:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![twelve20](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@twelve20](https://forum.kirupa.com/u/twelve20)\
**Post date:** [September 21, 2009, 12:05pm UTC](https://forum.kirupa.com/t/pre-replace-not-sure-what-the-correct-expression-is/296816/1 "2009-09-21T12:05:01Z")

</div>

Hi all

I need to scan a block of body copy that will replace certain words within the copy with other words.

I can do this is and got this part working.

How ever i need it to replace only words out side of any html tags. \<._\> \</._\> \< /\>

So if the word appears in a link its ignored.

Any ideas on how to do this?

my code so far

```php

$patterns[] = '/'.$tag.'(?![^<]*>)/i';
$replacements[] = '<a href="'/'.$tag.'" >'.$tag.'</a>';

```

Thanks
