Python regex: XOR operator
<p>Suppose I have strings like these:</p>

<ol>
<li><code>"DT NN IN NN"</code></li>
<li><code>"DT RB JJ NN"</code></li>
<li><code>"DT JJ JJ NN"</code></li>
<li><code>"DT RB RB NN NN"</code></li>
<li><code>"DT RB RB"</code></li>
</ol>

<p>So, I have a list of strings:</p>

<pre><code>list = ["DT NN IN NN", "DT RB JJ NN", "DT JJ JJ NN", "DT RB RB NN NN", "DT RB RB"]
</code></pre>

<p>I have the following code:</p>

<pre><code>pattern = "(?:DT\s+)+([?:RB\s+|?:JJ\s+])+(?:NN\s+)*NN$"
for item in list:
    m = re.match(pattern, item)
    if m:
        print item
</code></pre>

<p>What I want from <code>pattern</code> is to match the strings that start with <code>DT</code> (appears one or more times) have either <code>RB</code> or <code>JJ</code> (appearing once or more), but not both, and then to end with <code>NN</code> (again, appearing once or more). </p>

<p>So, in the final result I should get 3 and 4 printed on the screen. However, with my regex, in addition I get 2, which I don't want. How do I change <code>pattern</code> so this could work? How to replace the pipe (OR) with a XOR? </p>