我需要2組捕獲:1-expr(可以爲空); 2,ESSIPHP的正則表達式 - 需要2組捕獲
見下面的代碼
$s = 'regular expr<span>essi</span>on contains';
function my_func($matches){
//I need 2 groups captured
//$matches[1] - "expr" (see $s before span) - can be empty, but I still need to capture it
//$matches[2] - "essi" (between spans)
}
$pattern = "???";
echo preg_replace_callback($pattern, my_func, $s);
那麼,我已經回答了,但我不應該鼓勵這個,所以仍然存在這樣一個問題:你試過了什麼? –