The you could use a.index(b) to find at what position b starts as a
substring of a and use that to look backwards two characters and check
them if they are acceptable.
def is_match(a, b)
pos = a.index(b)
if pos == nil
return false
elsif pos < 2
# we matched within the first 2 characters of the string
# there is not enough room for special charaters
return true
elsif a[pos-2,2] == '@@'
return false
else
return true
end
end
Warning! Untested code, just written in the email.