-2

Detect any URLs in a plain-text and convert em into links, but if its already a link, do nothing.

var text = 'text with link <a href="/">www.google.com</a>, another link www.google.com';

the result should be:

var text = 'text with link <a href="/">www.google.com</a>, another link <a href="www.google.com">www.google.com</a>';
Tushar
  • 85,780
  • 21
  • 159
  • 179
  • @GopikrishnaS—not really a duplicate, that question is about just URIs in strings, but this question wants to also ignore existing HTML links in text and only convert plain text URIs. – RobG Mar 08 '16 at 04:43

1 Answers1

1

You can parse with a regexp than looks for urls (search google for examples). Then you need get the index of the string (the located url ) inside de text and make the change (put an "a" attribute arround the link). Then get again other index, until get the EOF.

  • Can you show me how to do that? – Eric Borchert Mar 08 '16 at 04:26
  • This isn't an answer. If you can write a regular expression that will do this reliably and robustly in a general case (i.e. not limited by protocol, port, fragment, query, etc.), then you are able to do something that no one else has been able to do. – RobG Mar 08 '16 at 04:47
  • RobG: Maybe is not the best way, but this will work, because simply I'm looking for a string inside a string and then I can append to them every thing I want. – Franco Gimenez Mar 09 '16 at 17:49