Need Regular Expression To Convert all URL to links in a paragraph

Home Forums Web Development ASP.Net Need Regular Expression To Convert all URL to links in a paragraph

This topic contains 0 replies, has 2 voices, and was last updated by  Nitesh 5 years, 7 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #3428

    Nitesh
    Member

    Hello,

    I have a requirement where user can enter a large paragraph of text which contains website url’s and some E-mail Id’s.
    i need a regular expressions to convert all website url’s in paragraph to clickable links
    and also convert all E-mail Id’s to mailto: links.

    #3435

    try this code snippet:

    
    
    static string ReplaceURl(Match m)
    {
      string x = m.ToString();
      x = "< a href=\"" + x + "\">" + x + "";
      return x;
    }
    static string ReplaceEmail(Match m)
    {
      string x = m.ToString();
      x = "Mailto:" + x;
      return x;
    }
    private void ModifyString()
    {
      string input = "find more on http://www.authorcode.com or you can email to" +
                     " contactus@authorcode.com";
      Regex regx = new Regex(@"\b((http|https|ftp|mailto)://)?(www.)+[\w-]+(/[\w- ./?%&=]*)?");
      string result = regx.Replace(input, new MatchEvaluator(ReplaceURl));
      regx = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
      result = regx.Replace(result, new MatchEvaluator(ReplaceEmail));
    }
    
    
    #3446

    Nitesh
    Member

    thanx alot

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.