title: Is it possible to match any character that is not ']' in PATINDEX?
body: <p>I need to find the index of the first character that is not <code>]</code>. Normally to match any character except <code>X</code>, you use the pattern <code>[^X]</code>. The problem is that <code>[^]]</code> simply closes the first bracket too early. The first part, <code>[^]</code>, will match any character.</p>
  
  <p>In the documentation for the <a href="https://msdn.microsoft.com/en-us/library/ms179859.aspx" rel="nofollow noreferrer"><code>LIKE</code> operator</a>, if you scroll down to the section "Using Wildcard Characters As Literals" it shows a table of methods to indicated literal characters like <code>[</code> and <code>]</code> inside a pattern. It makes no mention of using <code>[</code> or <code>]</code> inside double brackets. If the pattern is being used with the <code>LIKE</code> operator, you would use the <code>ESCAPE</code> clause. <code>LIKE</code> doesn't return an index and <code>PATINDEX</code> doesn't seem to have a parameter for an escape clause.</p>
  
  <p>Is there no way to do this?</p>
  
  <p>(This may seem arbitrary. To put some context around it, I need to match <code>]</code> immediately followed by a character that is not <code>]</code> in order to locate the end of a quoted identifier. <code>]]</code> is the only character escape inside a quoted identifier.)</p>