title: perl regex negative set matching string in negative lookahead
body: <p>I'm trying to match any set of characters (inside square brackets) other then square brackets (<code>[^\[\]]+</code>) -- unless the last part of the string of characters matches <code>-notme</code>.</p>
  
  <pre><code>perl -sp -e 'if (/\[[^\[\]]+?(?!-notme)\]$/../^no/)
   { print "#"; s/^yes/$VAR/; }' -- -VAR="CHANGED" /tmp/input
  </code></pre>
  
  <p>My input file looks like this:</p>
  
  <pre><code>-bash-4.2# cat /tmp/input 
  [test-ing]
  yes
  yes
  no
  maybe
  
  [test-ing-notme]
  yes
  yes
  no
  maybe
  </code></pre>
  
  <p>But my output looks like:</p>
  
  <pre><code>#[test-ing]
  #CHANGED
  #CHANGED
  #no
  maybe
  
  #[test-ing-notme]
  #CHANGED
  #CHANGED
  #no
  maybe
  </code></pre>
  
  <p>My speculation is that the negative set is matching what my negative lookahead should be not matching -- hence my attempt with lazy matching of the negative set, but the result is the same as if it were a greedy match.</p>
  
  <p>My expectation would be that the output would look like:</p>
  
  <pre><code>#[test-ing]
  #CHANGED
  #CHANGED
  #no
  maybe
  
  [test-ing-notme]
  yes
  yes
  no
  maybe
  </code></pre>