I agree with both Andrew and dpant. Due to the innumerable variations possible in URL's, it is much better to use a generic method such as the Uri class, rather than treating it as a string.
On Oct 7, 4:28 pm, dpant <[email protected]> wrote: > I wouldn't recommend using a regex since it is going to be a very > complicated one. > You can always use the string methods, for example: > > const string http = @"http://"; > const string url = @"http://www.foo.gr/f1/f2/f3/page.htm"; > string[] folders = url.Substring(http.Length).Split(new > char[] { '/' }); > > for (int i = 1; i < folders.Length; i++) > Console.WriteLine(folders[i]); > Console.ReadLine(); > > Hope that helps. > > On Oct 5, 6:45 pm, "C." <[email protected]> wrote: > > > > > Hi all, > > > I need to capture all the folders in a URL with a regex, but I can't > > get the pattern. > > > I've tried @"(http://[^/])?/(?<folders>[^/]*)/([^/]*)\.[^/]*", but it > > doesn't work. What pattern can I use to return a capture group that I > > can iterate through and extract all the directories within a URL? > > > Regards, > > > Chris- Hide quoted text - > > - Show quoted text -
