I was trying to do it with positive lookaheads/lookbehinds like so
\[datetime:[\w\-]+(?<=.?M{2}.?)\]
to match the presense of MM somewhere in code. But this doesn't work.
Lookbehinds are cumbersome to work with, as they are restricted on several levels in different engines (if supported at all). Also, your current code requires the MM to be contained in the last three chars of the datetime string, which seems not be what you want (an equivalent without lookbehind: \[datetime:[\w\-]*M{2}[\w\-]?\]
).
Better use lookaheads:
\[datetime:(?=.*?y{4})(?=.*?M{2})(?=.*?d{2})…[\w\-]+\]