Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Converting an URL to a link

Converting an URL to a link

Scheduled Pinned Locked Moved ASP.NET
htmlregexquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nikneem2005
    wrote on last edited by
    #1

    Hey guys, I'm trying to create html links of all URL's in a string. I'm calling the function below which seems to be pretty close to my needs, except for when someone enters a link followed by text directly after the url. Somebody with a 'proven technology' solution? public static string LinkText(string Input) { Regex urlregex = new Regex(@"(http:\/\/([\w.]+\/?)\S*)", RegexOptions.IgnoreCase | RegexOptions.Compiled); string Output = urlregex.Replace(Input, "[$1](\"$1\")"); Regex emailregex = new Regex(@"([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)", RegexOptions.IgnoreCase | RegexOptions.Compiled); Output = emailregex.Replace(Output, "[$1](mailto:$1)"); return Output; }


    I love it when a plan comes together http://www.zonderpunt.nl[^]

    V 1 Reply Last reply
    0
    • N nikneem2005

      Hey guys, I'm trying to create html links of all URL's in a string. I'm calling the function below which seems to be pretty close to my needs, except for when someone enters a link followed by text directly after the url. Somebody with a 'proven technology' solution? public static string LinkText(string Input) { Regex urlregex = new Regex(@"(http:\/\/([\w.]+\/?)\S*)", RegexOptions.IgnoreCase | RegexOptions.Compiled); string Output = urlregex.Replace(Input, "[$1](\"$1\")"); Regex emailregex = new Regex(@"([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)", RegexOptions.IgnoreCase | RegexOptions.Compiled); Output = emailregex.Replace(Output, "[$1](mailto:$1)"); return Output; }


      I love it when a plan comes together http://www.zonderpunt.nl[^]

      V Offline
      V Offline
      Vasudevan Deepak Kumar
      wrote on last edited by
      #2

      Another RegEx is here: http://www.liamdelahunty.com/tips/php_convert_url_to_link.php[^]

      Vasudevan Deepak Kumar Personal Homepage Tech Gossips

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups