Assuming you only want to disallow strings that match the regex completely (i.e., mmbla
is okay, but mm
isn't), this is what you want:
^(?!(?:m{2}|t)$).*$
(?!(?:m{2}|t)$)
is a negative lookahead; it says "starting from the current position, the next few characters are not mm
or t
, followed by the end of the string." The start anchor (^
) at the beginning ensures that the lookahead is applied at the beginning of the string. If that succeeds, the .*
goes ahead and consumes the string.
FYI, if you're using Java's matches()
method, you don't really need the the ^
and the final $
, but they don't do any harm. The $
inside the lookahead is required, though.