title: Regex lookahead/lookbehind match for SQL script
body: <p>I'm trying to analyse some SQLCMD scripts for code quality tests. I have a regex not working as expected:</p>
  
  <pre><code>^(\s*)USE (\[?)(?&lt;![master|\$])(.)+(\]?)
  </code></pre>
  
  <p>I'm trying to match:</p>
  
  <ol>
  <li>Strings that start with USE (ignore whitespace)</li>
  <li>Followed by optional square bracket</li>
  <li>Followed by 1 or more non-whitespace characters.</li>
  <li>EXCEPT where that text is "master" (case insensitive)</li>
  <li>OR EXCEPT where that that text is a <code>$</code> symbol</li>
  </ol>
  
  <p>Expected results:</p>
  
  <p><code>USE [master]</code> - don't match</p>
  
  <p><code>USE [$(CompiledDatabaseName)]</code> - don't match</p>
  
  <p><code>USE [anything_else.01234]</code> - match</p>
  
  <p>Also, the same patterns above without the <code>[</code> and <code>]</code> characters.</p>
  
  <p>I'm using Sublime Text 2 as my RegEx search tool and referencing this <a href="https://github.com/dmikalova/sublime-cheat-sheets/blob/master/cheat-sheets/Regular%20Expressions.cheatsheet" rel="nofollow">cheatsheet</a></p>