1
,如果我有這樣一個字符串「富(酒吧)」,用下面的代碼,我可以幾乎解析它的方式我想:PHP的preg_match得到功能樣串
$results = array();
preg_match("/\w*(?=(\(.*\))?)/", 'foo(bar)', &$results);
print_r($results);
/*
Array
(
[0] => foo
[1] => (bar)
)
*/
我怎樣才能修改正則表達式有bar
而不是(bar)
?由於
有爲什麼要使用向前看什麼特別的原因?通常'/(\ w +)\((\ w +)\)/'就足夠了。 – Amarghosh 2010-04-28 10:40:46