2016-01-21 42 views
-2

我可以有很長的文字可以包含以下任一:正則表達式來發現寫成文字的網址,而不是鏈接

http://desktop.com/ 

<a href="http://desktop.com/" target="_blank" data-mce-href="http://desktop.com">http://desktop.com</a> 

我的查詢是,我需要得到所有當前沒有出現在使用正則表達式的鏈接上的獨立網址,然後我將把獨立網址更改爲鏈接。

此外,還有一點是,鏈接可以出現在文本中的任何位置,在行的開始/結束處/結束處。

+0

註冊精通使用HTML:請仔細閱讀本:http://stackoverflow.com/questions/1732348/regex-match- open-tags-except-xhtml-self-contained-tags – epascarello

+0

基本上,您需要遍歷元素並檢查其文本是否包含鏈接。 – epascarello

回答

0

這裏是你的問題一個例子:-)

http://www.codesheet.org/codesheet/u9iMMlpq

 
var tweet = "Some tweek with a link to a site: http://www.codesheet.org/"; 

var pattern = /(HTTP:\/\/|HTTPS:\/\/)([a-zA-Z0-9.\/&?_=!*,\(\)+-]+)/i; 

var replace = "$1$2"; 

tweet = tweet.replace(pattern , replace); 

document.write(tweet); 




+0

這也會發現需要避免的第二類字符串中的網址。 –

相關問題