preg_match url模式

Mik*_*ics 0 javascript php file-get-contents preg-match

因为我无法找到问题的确切答案,所以我决定在这里寻求帮助.所以,我有一个页面内容,我得到file_get_contents并想要preg_match这个网址:

http://sample.com/Last/LastSearch.ashx?q=cnt=1&day=5&keyword=sample&location=15&view=v
Run Code Online (Sandbox Code Playgroud)

<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>
Run Code Online (Sandbox Code Playgroud)

请帮我.

Tim*_*ker 5

为什么不使用DOM?这就是它的意思......

如果你坚持使用正则表达式,请尝试(在PHP中)

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

或(在JavaScript中)

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