title: Regular expression "empty range in char class error"
body: <p>I got a regex in my code, which is to match pattern of url and threw error:</p>
  
  <pre><code>/^(http|https):\/\/([\w-]+\.)+[\w-]+([\w- .\/?%&amp;=]*)?$/
  </code></pre>
  
  <p>The error was "empty range in char class error". I found the cause of that is in <code>([\w- .\/?%&amp;=]*)?</code> part. Ruby seems to recognize <code>-</code> in <code>\w- .</code> as an operator for range instead of a literal <code>-</code>. After adding escape to the dash, the problem was solved.</p>
  
  <p>But the original regular expression ran well on my co-workers' machines. We use the same version of osx, rails and ruby: Ruby version is ruby 1.9.3p194, rails is 3.1.6 and osx is 10.7.5. And after we deployed code to our Heroku server, everything worked fine too. Why did only my environment have error regarding this regex? What is the mechanism of Ruby regex interpreting?</p>