-2

I can have long text which can contain either of the following :

http://desktop.com/

and

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

My query is that I need to get all the stand alone URLs which are not currently present at links using Regex as then I will change the standalone Urls to links.

Also, another point is that the links can appear anywhere in the text , at the starting/in-between/ending of a line.

Bhumi Singhal
  • 8,063
  • 10
  • 50
  • 76
  • Reg Exp with HTML: Please read this: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags – epascarello Jan 21 '16 at 13:42
  • Basically you will need to loop over the elements and check to see if their text contains a link. – epascarello Jan 21 '16 at 13:43

1 Answers1

0

here is a example to your question :-)

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);




studio-klik
  • 196
  • 1
  • 3