I’m trying to match letters C D F H I E1 E2 CR (case insensitive) and came up with this. It’ll match a single letter but wont match the E1 E2 CR. Actually it should. Whats the right way to do this?
preg_match('/^([C]|[D]|[F]|[H]|[I]|[E1]|[E2]|[CR]?)$/','CR')
Given the fairly limited and specific set of codes you’re checking, I’d suggest using
rather than a regex — it’ll run quicker than a regex and be easier to undersand and modify later on.