Using regex to find an exact pattern match in Ruby

Viewed 17838

How would I go about testing for an exact match using regex.

"car".match(/[ca]+/) returns true.

How would I get the above statement to return false since the regex pattern doesn't contain an "r"? Any string that contains any characters other than "c" and "a" should return false.

"acacaccc" should return true

"acacacxcc" should return false

5 Answers
Related