I have the following string:

```
Lorem ipsum Test dolor sit amet, consetetur sadipscing elitr, sed diam nonumy <a href="http://Test.com/url">Test</a> eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd sed Test dolores et ea rebum. Stet clita kasd gubergren, no sea <a href="http://url.com">Test xyz</a> takimata sanctus est Lorem ipsum dolor sit amet.

```

Now I would replace the string 'Test' outside of tags an not between tags (e.g. replaced with '1234').

```
Lorem ipsum 1234 dolor sit amet, consetetur sadipscing elitr, sed diam nonumy <a href="http://Test.com/url">Test</a> eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd sed 1234 dolores et ea rebum. Stet clita kasd gubergren, no sea <a href="http://url.com">Test xyz</a> takimata sanctus est Lorem ipsum dolor sit amet.

```

I started with this regex: `(?!<a[^>]*>)(Test)([^<])(?!</a>)`

But two problems are not solved:

1. The text 'Test' gets also replaced inside Tags (e.g. `<a href="http://Test.com/url">`)
2. Does the text between the tag not exactly match the searched text, it will be also replaced (e.g. `<a href="http://url">Test xyz</a>`)

I hope someone has a solution to solve this problem.