Assuming you want to completely ban strings that match the regex (i.e. mmbla is ok, but mm not), this is what you want:
^(?!(?:m{2}|t)$).*$
(?!(?:m{2}|t)$) is a negative lookahead ; he says: "Starting at the current position, the next few characters are not mm or t , and then the end of the line." The starting anchor ( ^ ) at the beginning ensures that the lookahead is applied at the beginning of the line. If it succeeds,. .* Goes ahead and consumes the string.
FYI, if you use the Java matches() method, you really don't need ^ and the final $ , but they do no harm. However, $ inside lookahead is required.
Alan Moore Apr 14 '10 at 13:52 2010-04-14 13:52
source share