0

I have text which contains URLS starting with http, https and www. for example,

text = "I want to open up www.google.com"

How can I convert www.google.com to its corresponding URL link in the same text?

I looked at https://gist.github.com/guillaumepiot/4539986. The # Replace url to link example works perfectly for URLS starting with http and https. How can I modify the regular expression in this example to work for URLs starting with www. Also, how will the corresponding HTML change?

I found many similar questions on the Internet but none of the answers to those questions worked for my case.

1 Answers1

0

The regex is:

/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/

For more info, see this answer : https://stackoverflow.com/a/8234912/4626943

Community
  • 1
  • 1
sayan
  • 1,418
  • 16
  • 32