I’ve a regular expression that’s looking for 2-3 upper case letters, together, ending in T and beginning with P, M, C or E. The regular expression, executed in PHP, looks like this:
<?php
# The string to match against
$DT = 'Sat, 26 Nov 2011 21:04:19 GMT';
# Returns "MT" as a match
preg_match('/[PMCE][A-Z]?T/', $DT, $matches);
# I've also tried this -- returns "M" as a match
preg_match('/P|M|C|E[A-Z]?T/', $DT, $matches);
The second character is marked as optional with the ? but shouldn’t it only be capable of returning PT, MT, CT, ET, or P*T, M*T, C*T, E*T?
This regular expression should not be matching the above string, I thought? I’ve actually already worked around with non-regular expression methods, but I’d like to know what the heck I’m doing wrong. How is it possible that “MT” is a match to either of those expressions?
In English I thought the both read “The character P,M,C,or E possibly followed by any A-Z character, followed by a T.
Both of these are matching against the GMT. If you want it to be its own word make it match a space, like this: