2016-11-08 104 views
0

https://github.com/sorensen/absolutify實現一個漂亮的正則表達式來匹配相對URL:匹配相對URL

/(=["'])(([.]+\/)|(?:\/)|(\w|\#))(?!\/)/g 

雖然這種模式匹配正確的路徑,它不會匹配相關文件(如在<a href="index.html">foo</a>

會是什麼的優化,優雅的正則表達式看起來像,匹配相關文件,但不是有效的URL,如//example.com,http://example.com,https://example.com/foo等?

+0

它如何不匹配? 'var str ='=「index.html」'; console.log('matches?'+ str.match(/(=["'])(([.]+\/)|(?:\ /)|(\ w | \#))(?!\ /)/克));' – arhak

回答