0
比賽是否有可能使文字的兩場比賽 - /123/123/123?edit
兩個或更多的表達
我需要匹配123
,123
,123
和edit
對於第(123123123):模式是 - ([^\/]+)
對於第二(編輯):模式是 - ([^\?=]*$)
是否有可能在一個preg_match_all
功能相匹配,或者我需要做兩次 - 1噸ime爲一種模式,第二種爲第二種?
謝謝!
比賽是否有可能使文字的兩場比賽 - /123/123/123?edit
兩個或更多的表達
我需要匹配123
,123
,123
和edit
對於第(123123123):模式是 - ([^\/]+)
對於第二(編輯):模式是 - ([^\?=]*$)
是否有可能在一個preg_match_all
功能相匹配,或者我需要做兩次 - 1噸ime爲一種模式,第二種爲第二種?
謝謝!
您可以用單一preg_match_all
調用做到這一點:
$string = '/123/123/123?edit';
$matches = array();
preg_match_all('#(?<=[/?])\w+#', $string, $matches);
/* $matches will be:
Array
(
[0] => Array
(
[0] => 123
[1] => 123
[2] => 123
[3] => edit
)
)
*/
模式((?<=[/?])\w+
)在操作中查看使用lookbehind斷言,斜線或一個問號必須在字符序列之前(\w
是shorthand class相當於)。
太棒了!謝啦! – 2010-09-27 05:18:54