Tag:javascript正则表达式
Article From:https://segmentfault.com/q/1010000012147629
Question:
    function replaceURLToLink(text) {
     const reg = /((http|https):\/\/[\w.\/]+)(?![^<]+>)/gi
     return text.replace(reg,"<a href='$1' target='_blank'>$1</a>")
    }
    // At present, this can only be matched to HTTP (s): //www.baidu.com, and how to optimize the format of http://baidu.com/index/search? Keyword=123?

Answer 0:
<style>
    a{color:red;}
</style>

<h1>This is the link: http://www.baidu.com. Test < /h1>< script>Var H1 = document.getElementsByTagName ('H1') [0];H1.innerHTML = h1.innerHTML.replace (/ (http|ftp|https): \/\/[\w\-_]+ (\.[\w\-_]+) + ([\w\-\)?? @? ^=%&: /~\+#]*[\w\-\@? ^=%& / [+]] /g;'< a href= "$1" > $1< /a> ");< /script>

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *