<p>I need help to replace all \n (new line) caracters for <br /> in a String, but not those \n inside [code][/code] tags.
My brain is burning, I can't solve this by my own :(</p>

<p>Example:</p>

<pre><code>test test test
test test test
test
test

[code]some
test
code
[/code]

more text
</code></pre>

<p>Should be:</p>

<pre><code>test test test&lt;br /&gt;
test test test&lt;br /&gt;
test&lt;br /&gt;
test&lt;br /&gt;
&lt;br /&gt;
[code]some
test
code
[/code]&lt;br /&gt;
&lt;br /&gt;
more text&lt;br /&gt;
</code></pre>

<p>Thanks for your time.
Best regards.</p>

I would suggest a (simple) parser, and not a regular expression.  Something like this (bad pseudocode):
```
```
stack elementStack;

foreach(char in string) {
    if(string-from-char == "[code]") {
        elementStack.push("code");
        string-from-char = "";
    }

    if(string-from-char == "[/code]") {
        elementStack.popTo("code");
        string-from-char = "";
    }

    if(char == "\n" && !elementStack.contains("code")) {
        char = "<br/>\n";
    }
}
```
```