2016-11-08 77 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

回答