title: Regex negative look ahead to match markdown links
body: <p>We are stuck over a regex issue.</p>
  
  <p>Here is the problem. Consider the following two patterns: </p>
  
  <p>1) <code>[hello] [world]</code></p>
  
  <p>2) <code>[hello [world]]</code></p>
  
  <p>We need to write a regex able to match only <code>[world]</code> in the first one and the entire pattern (<code>[hello [world]]</code>) in the second.</p>
  
  <p>By using the negative lookahead, I wrote the following regex which solves part of the problem: </p>
  
  <pre><code>\[[^\[\]]+\](?!.*\[[^\[\]]+\])
  </code></pre>
  
  <p>This regex matches pattern 1) as we want, but does not work for pattern 2). </p>