Python re.search Patterns : <p>I have a bunch of strings that consist of Q, D or T. Below are some examples.</p>

<pre><code>              aa= "QDDDDQDTDQTD"
              bb = "QDT"
              cc = "TDQDQQDTQDQ"
</code></pre>

<p>i am new to re.search, for each string, is it possible to get all patterns with any length that start with Q, and ends with D or Q, and there is no T in between the first Q and the last D or Q. </p>

<p>So for aa, it would find "QDDDDQD"</p>

<p>for bb, it would find "QD"</p>

<p>for cc, it would find "QDQQD" and "QDQ" </p>

<p>I understand the basic forms of using re.search like:</p>

<pre><code>              re.search(pattern, my_string, flags=0)
</code></pre>

<p>Just having trouble how to set up the patterns mentioned above, like how to find patterns start with Q, or ends with Q, etc. Any help would be greatly appreciated!</p>
