krrishna
krrishna

Reputation: 2078

regular expression to extract the website address

I am trying to extract the websites(e.g. http://wwww.yogacenter.com:4355 )from the text given. But I am not getting any match with the below code. Any suggestions ?

        string pattern = @"\b(\S+)://(S+)(?::(\S+))?\b";
        string text = "i have just found this http://wwww.yogacenter.com:4355 at my  place.It's a http:// site.";
        MatchCollection mc = Regex.Matches(text, pattern);
        foreach (Match item in mc)
        {
            Console.WriteLine(item.Value);
        }

Upvotes: 1

Views: 71

Answers (1)

Viktor Justo
Viktor Justo

Reputation: 203

"\b(\S+)://(S+)(?::(\S+))?\b" I believe your problem lies in the missing backslash before the 2nd S

Upvotes: 1

Related Questions