title: Why is $1 not being set by my regular expression match?
body: <p>I have the code as below:</p>
  
  <pre><code>require 'colored'
  require 'byebug'
  
  str = '英 [faɪnd] 美 [faɪnd]'
  regex = /\[([^\[\]]*)\]/
  blk = Proc.new{|mat| mat.send(:yellow)}
  
  to_search = str.dup
  while regex =~ to_search do
    byebug
    str.sub! /#{$1}/, blk.call($1)
    ...
  end
  </code></pre>
  
  <p>Before <code>str.sub! /#{$1}/, blk.call($1)</code>,</p>
  
  <ul>
  <li><code>$1</code>  is <code>"faɪnd"</code></li>
  <li><code>$'</code> is <code>" 美 [faɪnd]"</code></li>
  </ul>
  
  <p>After it,</p>
  
  <ul>
  <li><code>$1</code> is <code>nil</code></li>
  <li><code>$'</code> is <code>"] 美 [faɪnd]"</code></li>
  </ul>
  
  <p>Why does this happen?</p>