简体   繁体   English

如何在href属性中找到缺少协议的HTML链接?

[英]How do I find HTML links missing the protocol in the href attribute?

I'm trying to find incorrectly written links like this: 我试图找到这样写不正确的链接:

<a href="mydomain.com">link</a>

I've got this regex: 我有这个正则表达式:

href *= *"? *(?!http|https|ftp)

But if doesn't work... any ideas? 但是,如果行不通……有什么想法吗?

Thanks 谢谢

Using GNU grep : 使用GNU grep

% echo '
<a href="http://mydomain.com">link</a>
<a href="https://mydomain.com">link</a>
<a href="ftp://mydomain.com">link</a>
<a title="My Domain"
   href="mydomain.com">link</a>
' | grep --perl -o 'href[[:space:]]*=[[:space:]]*"(?!(ht|f)tps?://)[^"]+"'
href="mydomain.com"

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

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