```
some text here
<span class="my--class-name--here" id="some--id">some -- text--here</span> 
test text--here
<div class="another--class-name">test --test</div>
<!--[if IE 9]><video style="display: none;"><![endif]-->

```

For the above content, I want some help in writing code to replace all occurrence of double dash (`--`) with `&mdash;`.

But, it should not replace the double dash for any attributes inside the html elements. For e.g., the double dash in the class name (`my--class-name--here`) and id name (`id="some--id"`) should not replaced.
And, also it should not replace double dash in `<!--[if IE 9]>` and `<![endif]-->`
['https://Stackoverflow.com/questions/26172820', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1227325/']
If you are wanting a one-liner to replace outside of `<` and `>`, you can use the following.

```
$html = preg_replace('~<[^>]*>(*SKIP)(*F)|--~', '—', $html);

```

The idea is to skip any content that is located between an opening and closing bracket character.

On the left side of the alternation operator we match the subpattern we do not want. Making it fail and forcing the regular expression engine to not retry the substring using backtracking control verbs.

[`Working Demo`](https://eval.in/201333)
Use a negative lookahead to match `--` which was not inside any html tags.

```
--(?![^><]*>)

```

Replace the matched `--` with `—`.

[DEMO](http://regex101.com/r/lJ1fL0/2)

```
<?php
$string = <<<EOT
some text here
<span class="my--class-name--here" id="some--id">some -- text--here</span> 
test text--here
<div class="another--class-name">test --test</div>
<!--[if IE 9]><video style="display: none;"><![endif]-->
EOT;
echo preg_replace('~--(?![^><]*>)~', '—', $string);
?>

```

Output:

```
some text here
<span class="my--class-name--here" id="some--id">some — text—here</span> 
test text—here
<div class="another--class-name">test —test</div>
<!--[if IE 9]><video style="display: none;"><![endif]-->

```