2011-05-24 48 views
0

因爲我無法找到確切的答案給我的問題我決定尋求幫助張貼我的問題在這裏。所以,我有一個頁面的內容,我得到與file_get_contents,並希望preg_match這個網址:preg_match url pattern

http://sample.com/Last/LastSearch.ashx?q=cnt=1&day=5&keyword=sample&location=15&view=v 

<a href="javascript:LastURL('http://sample.com/Last/LastSearch.ashx?q=cnt=1&day=5&keyword=sample&location=15&view=v');" id="Last" rel="nofollow" class="Last" onclick="javascript:hideCss('LastCSS');hideCss('FirstRCSS');">Last</a> 

請幫助我。

+1

* COFF *'filter_var' * COFF * – RobertPitt 2011-05-24 11:46:40

回答

5

爲什麼不使用DOM?這就是它是...

如果你堅持一個正則表達式,試(在PHP)

if (preg_match('/<a href="javascript:LastURL\(\'([^\'])*\'/', $subject, $regs)) { 
    $result = $regs[1]; 
} else { 
    $result = ""; 
} 

或(在JavaScript)

var myregexp = /<a href="javascript:LastURL\('([^'])*'/; 
var match = myregexp.exec(subject); 
if (match != null) { 
    result = match[1]; 
} else { 
    result = ""; 
} 
+1

**了它:**'preg_match('/ Mikerobenics 2011-05-24 12:15:57

0

只要URL總是會以http://那麼你可以使用你的preg_match內的下列表達式:

(((f|ht){1}tp://)[[email protected]:%_\+.~#?&//=]+) 
+1

'(f | ht){1}'=='(f | ht)'。暗示「{1}」。 – jensgram 2011-05-24 11:31:10

+0

以及如何在我的情況下使用它? – Mikerobenics 2011-05-24 11:58:57