I am making a preg\_replace on html page. My pattern is aimed to add surrounding tag to some words in html. However, sometimes my regular expression modifies html tags. For example, when I try to replace this text:

```
<a href="example.com" alt="yasar home page">yasar</a>

```

So that `yasar` reads `<span class="selected-word">yasar</span>` , my regular expression also replaces yasar in alt attribute of anchor tag. Current `preg_replace()` I am using looks like this:

```
preg_replace("/(asf|gfd|oyws)/", '<span class=something>${1}</span>',$target);

```

How can I make a regular expression, so that it doesn't match anything inside a html tag?