This post shows you How to Detect URL in text using Regular Expression in C#.

If you want to detect urls contained in a string using c#, you can use this code below.

c# find url from text

static void Main(string[] args)
    string txt = "This is my site and you can visit my forum at";
    if (Regex.IsMatch(txt, @"(http|ftp|https):\/\/([\w\-_]+(??:\.[\w\-_]+)+))([\w\-\.,@?^=%&~\+#]*[\w\-\@?^=%&/~\+#])?"))
        //Do something

c# get url from string

string text = "This is my url and visit this website and this is my url";
List<string> urls = new List<string>();
foreach (var url in Regex.Matches(text, @"(http|ftp|https):\/\/([\w\-_]+(??:\.[\w\-_]+)+))([\w\-\.,@?^=%&amp;~\+#]*[\w\-\@?^=%&amp;/~\+#])?"))

Through this c# example, you can learn how to use regular expression in c# to helps you find url from string or get url from string in c#.