我想将网页内不包含 http://
等协议(protocol)的链接的 .html
扩展名替换为 JavaScript
和 https://
以确保它们是本地链接。
我尝试过类似的方法,但无法正常工作:
字符串
<a href="local/path/to/url.html"> Replace me </a>
<a href="http://external.com/to/url.html"> DON'T replace me </a>
<a href="https://external.com/to/url.html"> DON'T replace me </a>
正则表达式
/href="^(http:|https:)(.*?).html"/gm
我不清楚如何在正则表达式中否定协议(protocol),如果我放置它们没有任何匹配。
最佳答案
关于javascript - 如果是本地的,则替换 href 链接扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26234481/