title: difference b/w [ab] and (a|b) in regex match?
body: <p>I knew that <code>[]</code> denotes a set of allowable characters - </p>
  
  <pre><code>&gt;&gt;&gt; p = r'^[ab]$'
  &gt;&gt;&gt; 
  &gt;&gt;&gt; re.search(p, '')
  &gt;&gt;&gt; re.search(p, 'a')
  &lt;_sre.SRE_Match object at 0x1004823d8&gt;
  &gt;&gt;&gt; re.search(p, 'b')
  &lt;_sre.SRE_Match object at 0x100482370&gt;
  &gt;&gt;&gt; re.search(p, 'ab')
  &gt;&gt;&gt; re.search(p, 'ba')
  </code></pre>
  
  <p>But ... today I came across an expression with vertical bars within parenthesis to define mutually exclusive patterns - </p>
  
  <pre><code>&gt;&gt;&gt; q = r'^(a|b)$'
  &gt;&gt;&gt; 
  &gt;&gt;&gt; re.search(q, '')
  &gt;&gt;&gt; re.search(q, 'a')
  &lt;_sre.SRE_Match object at 0x100498dc8&gt;
  &gt;&gt;&gt; re.search(q, 'b')
  &lt;_sre.SRE_Match object at 0x100498e40&gt;
  &gt;&gt;&gt; re.search(q, 'ab')
  &gt;&gt;&gt; re.search(q, 'ba')
  </code></pre>
  
  <p>This seems to mimic the same functionality as above, or am I missing something?</p>
  
  <p>PS: In <code>Python</code> parenthesis themselves are used to define logical groups of matched text. If I use the second technique, then how do I use parenthesis for both jobs?</p>