=begin
Character Classes
delimited with square brackets ([, ])
diff between /[ab]/ and /ab/
hyphen (-) is a metacharacter denoting an inclusive range.
=> [abcd] = [a-d]
=> [abcdwxyz] = [a-dw-z] (order does not matters)
caret (^) the class is inverted
is reserve in character class to represent range
^ inside character class negates the match
Note. Only - ^ and ] are reserved.
=end
p /[ab]/ =~ "rails"
p /[a-d]/ =~ "god"
p /[^abc]/ =~ "money"
p /[ab^c]/ =~ "r ^ugby"
=begin Character Classes delimited with square brackets ([, ]) diff between /[ab]/ and /ab/ hyphen (-) is a metacharacter denoting an inclusive range. => [abcd] = [a-d] => [abcdwxyz] = [a-dw-z] (order does not matters) caret (^) the class is inverted
=end
p /[ab]/ =~ "rails" p /[a-d]/ =~ "god" p /[^abc]/ =~ "money" p /[ab^c]/ =~ "r ^ugby"