You could either use a lookahead assertion like others have suggested. Or, if you just want to use basic regular expression syntax:
^(.?$|[^m].+|m[^y].*)
This matches strings that are either zero or one characters long (^.?$
) and thus can not be my
. Or strings with two or more characters where when the first character is not an m
any more characters may follow (^[^m].+
); or if the first character is a m
it must not be followed by a y
(^m[^y]
).