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


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

我试图找到这样写得不正确的链接:

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

我有一个正则表达式:

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

但如果不起作用。。。有什么想法吗?

感谢

使用GNUgrep

% 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"