开发者

Regular expression matching href=

开发者 https://www.devze.com 2023-03-31 22:55 出处:网络
I\'ve been looking for a few days now, trying to match href links but I need to reduce the results so that the start of the href is:

I've been looking for a few days now, trying to match href links but I need to reduce the results so that the start of the href is:

开发者_运维问答
<a href="/hp/

Does anyone know a regular expression that could do this?


preg_match('/<a href=["\']?(\/load\/[^"\'\s>]+)["\'\s>]?/i', $string);

This matches:

<a href="/load/anytext">

and returns its href value, but not

<a href="http://www.example.com">

Pay attention: if you want the regex to match also href="/load/" without other text then you have to substitute the + before the ? with a *, else this regex matches only href="/load/anytext..."

0

精彩评论

暂无评论...
验证码 换一张
取 消