I asked a similar question recently about using regex to retrieve a URL or folder path from a string. I was looking at this comment by Dour High Arch, where he says:
"I recommend you do not use regexes at all; use separate code paths for URLs, using the Uri class, and file paths, using the FileInfo class. These classes already handle parsing, matching, extracting components, and so on."
I never really tried this, but now I am looking into it and can't figure out if what he said actually is useful to what I'm trying to accomplish.
I want to be able to parse a string message that could be something like:
"I placed the files on the server at http://www.thewebsite.com/NewStuff, they can also be reached on your local network drives at J:\Downloads\NewStuff"
And extract out the two strings http://www.thewebsite.com/
and J:\Downloads\NewStuff
. I don't see any methods on the Uri
or FileInfo
class that parse a Uri
or FileInfo
object from a string like I think Dour High Arch was implying.
Is there something I'm missing about using the Uri
or FileInfo
class that will allow this behavior? If not is there some other class in the framework that does this?