You can use positive lookahead and lookbehind, which is a zero-width match, to do it. A regex like (?<=^|\s)5 p\.m\.(?=\s|$)
means "Start of the string or a space character, followed by '5 p.m.' followed by anything which is a space character or end of string."