I have a very simple regex task that has left me confused (and just when I thought I was starting to get the hang of them too). I just want to check that a string consists of 11 digits. The regex I have used for this is /\d{11}/. My understanding is that this will give a match if there are exactly (no more and no less than) 11 numeric characters (but clearly my understanding is wrong).
Here is what happens in irb:
ruby-1.9.2-p136 :018 > "33333333333" =~ /\d{11}/
=> 0
ruby-1.9.2-p136 :019 > "3333333333" =~ /\d{11}/
=> nil
ruby-1.9.2-p136 :020 > "333333333333" =~ /\d{11}/
=> 0
So while I get an appropriate match for an 11 digit string and an appropriate no-match for a 10 digit string, I am getting a match on a 12 digit string! I would have thought /\d{11,}/ would be the regex to do this.
Can anyone explain my misunderstanding?