Code: Select all
define('POST_CODE', '/[ABCEGHJKLMNPRSTVXY]\d[A-Z] \d[A-Z]\d{1}/');I am using REGEX like this to facilitate my validation library. Ideally I would like the result of each operation to return the array of parts extracted using REGEX.
Is there any way to accomplish this, BUT, including a name with the array elements, so what is returned is:
Code: Select all
array
(
['FSA'] => 'R'
)Another issue I have with the above regex defined in POST_CODE is the fact that values like:
R2R1R2 => NO Match
R2R 1R2 => Match
R2R 1R22 => Still Match
The latter is what confuses me, how do make the regex stop matching at this point? Obviously the last is not valid.
I'm using preg_match -- should I use preg_match_all??? What is the difference? One is greedy? I thought that was indicated via a modifier?
Cheers,
Alex