title: RegEx in Ruby: Just one match?
body: <p>I'm trying to figure out how to check if a string matches a regular expression, <strong>but I want to know if the entire string matches just once</strong>. Here's my code but it seems absurdly long</p>
  
  <pre><code>def single_match(test_me, regex)
    ret_val = false
    test = regex.match(test_me)
    if (test.length==1 &amp;&amp; test[0].length == test_me.length)
        ret_val = true
    end
    return ret_val
  end
  </code></pre>
  
  <p>is there an easier way to do this?</p>
  
  <p>P.S. Here's the method I'm really trying to write, since people always seem to ask why I want the gun these days:</p>
  
  <pre><code>def is_int(test_me)
    return single_match(test_me, /[0-9]*/)
  end
  </code></pre>
  
  <p><strong>Edit</strong> Thanks everybody. <a href="https://stackoverflow.com/questions/230335/why-do-i-need-to-work-harder-to-make-my-rails-application-fit-into-a-restful-arch#486133">Here's where I'm really using it</a>, but this regex stuff is always interesting to go through. Thanks for the great and educational answers.</p>