2010-04-16 86 views
0

我試圖找到$_GET查詢字符串的正則表達式。

我有一個這樣的數組:

private $_regexp = array(
    ':id' => '[0-9]+', 
    ':year' => '[12][0-9]{3}', 
    ':month' => '0[1-9]|1[012]', 
    ':day' => '0[1-9]|[12][0-9]|3[01]', 
    ':slug' => '[a-zA-Z0-9-]+', 
    ':query' => '...' 
); 

我扔環路他們看到的,如果我有一個匹配的通配符是這樣的:

if (array_key_exists($matches[0], $this->_regexp)) 
    { 
     return '^('.$this->_regexp[$matches[0]].')$'; 
    } 

所有其他正則表達式去罰球,但我已經嘗試了很多不同的正則表達式來找到:

?anything=anything 

不能算出來,像谷歌搜索,但不能找到什麼。我試過,例如像這樣:

(\?)(.*)(=)(.*) 

但是沒有結果......

任何正則表達式大師在這裏?

/托比亞斯

回答

1

雖然我真的不明白的問題,你的正則表達式將是

\?([^=]+)=([^&]*) 
 
\?   # a literal question mark 
(   # group 1 
    [^=]+ # anything but a "=", 1-unlimited chars 
)   # end group 1 
=   # the "=" 
(   # group 2 
    [^&]* # anything but a "&", 0-unlimited chars 
)   # end group 2 

你能解釋一下你是什麼實際上意欲何爲?

0

如何: -

(\?)([^=]+)(=)(.+) 
相關問題