title: Inconsistency between $ and ^ in regex when using start/end arguments to re.search?
body: <p>From what I've read, <code>^</code> should match the start of a string, and <code>$</code> the end. However, with <code>re.search()</code>, it looks like the behavior of <code>^</code> continues to work fine, while <code>$</code> 'breaks'. Example:</p>
  
  <pre><code>&gt;&gt;&gt; a = re.compile( "^a" )
  &gt;&gt;&gt; print a.search( "cat", 1, 3 )
  None
  </code></pre>
  
  <p>This seems correct to me -- <code>'a'</code> is not at the start of the string, even if it is at the start of the search.</p>
  
  <pre><code>&gt;&gt;&gt; a = re.compile( "a$" )
  &gt;&gt;&gt; print a.search( "cat", 0, 2 )
  &lt;_sre.SRE_Match object at 0x7f41df2334a8&gt;
  </code></pre>
  
  <p>This seems wrong to me, or inconsistent at least.</p>
  
  <p>The documentation on the <code>re</code> module explicitly mentions that the behavior of <code>^</code> does not change due to start/end arguments to <code>re.search</code>, but no change in behavior is mentioned for <code>$</code> (that I've seen).</p>
  
  <p>Can anyone explain why things were designed this way, and/or suggest a convenient workaround?</p>
  
  <p>By workaround, I would like to compose a regex which always matches the end of the string, even when someone uses the end argument to <code>re.search</code>.</p>
  
  <p>And <em>why</em> was <code>re.search</code> designed such that:</p>
  
  <pre><code>s.search( string, endPos=len(string) - 1 )
  </code></pre>
  
  <p>is the same as</p>
  
  <pre><code>s.search( string[:-1] )
  </code></pre>
  
  <p>when</p>
  
  <pre><code>s.search( string, startPos=1 )
  </code></pre>
  
  <p>is explicitly and intentionally not the same as</p>
  
  <pre><code>s.search( string[1:] )
  </code></pre>
  
  <p>It seems to be less an issue of inconsistency between <code>^</code> and <code>$</code>, and more of an inconsistency within the <code>re.search</code> function.</p>