描述
这个正则表达式将:
- 在锚标签内找到 href 属性值
- 避免一些困难的边缘情况
<a\b(?=\s)(?=(?:[^>=]|='[^']*'|="[^"]*"|=[^'"][^\s>]*)*?\shr=.*?ef=3D['"]([^"]*)['"]?)(?:[^>=]|='[^']*'|="[^"]*"|=[^'"\s]*)*"\s?\/?>.*?<\/a>
例子
示例文本
注意 onmouseover 中的困难边缘情况
<a onmouseover=' href="NotTheHrefYoureLookingFor" ; funRotator(href) ; ' target=3D"_blank" href="http://abc.com/blog/check-your-cars-health-before-going-on-lo=
ng-trip/">link text
</a>
捕获组
[0] => <a onmouseover=' href=" hr=
ef=3D NotTheHrefYoureLookingFor" ; funRotator(href) ; ' target=3D"_blank" hr=
ef=3D"http://abc.com/blog/check-your-cars-health-before-going-on-lo=
ng-trip/">link text
</a>
[1] => http://abc.com/blog/check-your-cars-health-before-going-on-lo=
ng-trip/