-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>'; 
1
  • @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. Commented Mar 8, 2016 at 4:43

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Can you show me how to do that?
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: 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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.