简体   繁体   English

正则表达式匹配href =

[英]Regular expression matching href=

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: 我一直在找几天,试图匹配href链接,但是我需要减少结果,以便href的开头是:

<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 并返回其href值,但不返回

<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 ? 注意:如果您想让正则表达式也匹配href =“ / load /”而不包含其他文本,则必须在?之前替换+。 with a *, else this regex matches only href="/load/anytext..." 带有*,否则此正则表达式仅匹配href =“ / load / anytext ...”

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

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