Code: Select all
preg_match('#((?<found>a)(x|c))?#',"ab ax ac",$testresult);but if you remove the most outward parentheses:
Code: Select all
preg_match('#(?<found>a)(x|c)#',"ab ax ac",$testresult);The problem is that if it fails on first occurence for 'a' which is ax then it gives up completely and does not bother to check the rest of the string.Array ( [0] => ax [found] => a [1] => a [2] => x )
I need these outward parentheses because I want preg_replace to return true even if it not finds what I look for.