繁体   English   中英

preg_match url 模式

[英]preg_match url pattern

因为我找不到我的问题的确切答案,所以我决定寻求帮助,在这里发布我的问题。 所以,我有一个页面内容,我通过file_get_contents获得并希望preg_match这个 url:

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>

请帮我。

为什么不使用 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 = "";
}

只要 url 总是以 http:// 开头,那么您可以在 preg_match 中使用以下表达式:

(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM