-1

I was reading about the match method in ruby, I understood most of the example given at Regexp

But I am failing to understand, why is:

/[0-9a-f]/.match('9f')
=> #<MatchData "9">

And not:

=> #<MatchData "9f">

I might be missing some basic understanding of Regex, so bear with me.

harshs08
  • 700
  • 10
  • 29

1 Answers1

2

Because you're asking it to match a single character of class 0-9 or a-f.

If you want to match multiple use a plus or an asterisk after the character classes e.g. /[0-9a-f]+/.match('9f')

It's all here.

R. Hatherall
  • 1,121
  • 14
  • 11