0

My web page content is populated by a plain text that is retrieved from a CDATA format - plain text data.

This is the site http://checksite.apsx to get information.

For more information, visit http://moresites.com/FAQ/index.html or search the site.

Now, my goal is to convert this plain text to a valid hyperlinks. I've used a javascript code that does the conversion - /((http|https|ftp):\/\/[^ ]+)/g; , but sometimes if there are multiple words, it captures an invalid URL.

My question: Is there a way to strictly capture any string that starts with "http" AND ends with ".html" or "aspx" will be converted into a valid hyperlink?

it should look like this -

This is the site http://checksite.apsx to get information.

For more information, visit http://moresites.com/FAQ/index.html or search the site.

syntaxcode
  • 133
  • 2
  • 16
  • 2
    i didn't see any differences between the input and the expected output. – Avinash Raj Aug 19 '14 at 04:15
  • possible duplicate of [What is the best regular expression to check if a string is a valid URL?](http://stackoverflow.com/questions/161738/what-is-the-best-regular-expression-to-check-if-a-string-is-a-valid-url) – Braj Aug 19 '14 at 04:18
  • how any string starts with "http" AND ends with ".html" or "aspx" will be converted into a valid hyperlink? – Braj Aug 19 '14 at 04:18
  • This [SO post](http://stackoverflow.com/questions/161738/what-is-the-best-regular-expression-to-check-if-a-string-is-a-valid-url) discusses a universal regex for URL. – PM 77-1 Aug 19 '14 at 04:19
  • @user3218114 - I would venture a guess that OP meant "**could** be converted` – PM 77-1 Aug 19 '14 at 04:21
  • *sometimes if there are multiple words, it captures an invalid URL.* share some inputs. – Braj Aug 19 '14 at 04:22
  • @syntaxcode could you explain the edit? – Avinash Raj Aug 19 '14 at 04:33
  • I removed the {} from the 2nd output to show that it should display as hyperlink for each plain text with http:* url string. Is it possible to define the regex that ends with .html or .aspx and display as hyperlink using the same match from http:*...-.html or .aspx? – syntaxcode Aug 19 '14 at 04:43
  • @user3218114 - yes all instance of string starts with http:.... ends with .html or .aspx... – syntaxcode Aug 19 '14 at 04:46
  • @user3218114 - since this is from a CDATA content, not sure why sometimes extra lines are included in the hyperlink conversion... – syntaxcode Aug 19 '14 at 04:48

0 Answers0