title: regexp: match character group or end of line
body: <p>How do you match <code>^</code> (begin of line) and <code>$</code> (end of line) in a <code>[]</code> (character group)?</p>
  
  <hr>
  
  <p>simple example</p>
  
  <p>haystack string: <code>zazty</code></p>
  
  <p>rules:</p>
  
  <ol>
  <li>match any "z" or "y"</li>
  <li>if preceded by
  
  <ol>
  <li>an "a", "b"; or</li>
  <li>at the beginning of the line.</li>
  </ol></li>
  </ol>
  
  <p>pass:
  match the first two "z"</p>
  
  <p>a regexp that would work is:<br>
  <code>(?:^|[aAbB])([zZyY])</code></p>
  
  <p>But I keep thinking  it would be much cleaner with something like that meant beginning/end of line inside the character group<br>
  <code>[^aAbB]([zZyY])</code><br>
   (in that example assumes the <code>^</code> means beginning of line, and not what it really is there, a negative for the character group)</p>
  
  <hr>
  
  <p>note: using python. but knowing that on bash and vim would be good too.</p>
  
  <p>Update: read again the <a href="http://docs.python.org/library/re.html" rel="noreferrer">manual</a> it says for set of chars, everything lose it's special meaning, except the character classes (e.g. <code>\w</code>)</p>
  
  <p>down on the list of character classes, there's <code>\A</code> for beginning of line, but this does not work <code>[\AaAbB]([zZyY])</code></p>
  
  <p>Any idea why?</p>