As has been mentioned in the comments, your pattern is incorrect. It appears that you’re attempting to use a character class, but have neglected to include the surrounding square brackets. Your pattern, as it currently stands, will only match on strings that start with the literal text a-eg-h
. The pattern you want is:
/[^a-eg-h]/
Additionally, attempting to match the string j
with this pattern will fail and return nil
in Ruby, as the string does not match the pattern. A better way to go about this would be something like:
match = /[^a-eg-h]/.match(str)
if (match)
do_something()
end