<p>I want to write a regular expression that will replace the word Paris by a link, for only the word is not ready a part of a link.</p>

<p>Example:</p>

<pre><code>    i'm living &lt;a href="Paris" atl="Paris link"&gt;in Paris&lt;/a&gt;, near Paris &lt;a href="gare"&gt;Gare du Nord&lt;/a&gt;,  i love Paris.
</code></pre>

<p>would become </p>

<pre><code>    i'm living.........near &lt;a href=""&gt;Paris&lt;/a&gt;..........i love &lt;a href=""&gt;Paris&lt;/a&gt;.
</code></pre>

Regular expression:
```
```
!(<a.*</a>.*)*Paris!isU
```
```
Replacement:
```
```
$1<a href="Paris">Paris</a>
```
```
$1 referes to the first sub-pattern (at least in PHP). Depending on the language you use it could be slightly different.
This should replace all occurencies of "Paris" with the link in the replacement. It just checks whether all opening a-Tags were closed before "Paris".
PHP example:
```
```
<?php
$s = 'i\'m living <a href="Paris" atl="Paris link">in Paris</a>, near Paris <a href="gare">Gare du Nord</a>, i love Paris.'; 
$regex = '!(<a.*</a>.*)*Paris!isU'; 
$replace = '$1<a href="Paris">Paris</a>'; 
$result = preg_replace( $regex, $replace, $s); 
?>
```
```
Addition:
This is not the best solution. One situation where this regex won't work is when you have a img-Tag, which is not within an a-Element. When you set the title-Attribute of that image to "Paris", this "Paris" will be replaced, too. And that's not what you want.
Nevertheless I see no way to solve your problem completely with a simple regular expression.