title: Syntax error with $ anchor in regular expression
body: <p>The following Ruby script results in a syntax error:</p>
  
  <pre><code>test = 'Hello world#'
  test.sub!(/#$/, '!')
  p test
  </code></pre>
  
  <p>I'd expect the output to be <code>"Hello world!"</code>. From my understanding, the regex should match any hash character at the end of a line. Then <code>sub!</code> should replace it with an exclamation point.</p>
  
  <p>Instead, I'm getting the following error message:</p>
  
  <pre><code>tmp.rb:2: unterminated regexp meets end of file
  tmp.rb:2: syntax error, unexpected end-of-input, expecting ')'
  p test
        ^
  </code></pre>
  
  <p>It seems that the regex still continues after the second slash. If I change the regex to <code>/#/</code> (without the trailing <code>$</code>), it works as expected.</p>