Regular Expression to parse string url links

I am looking for a way to parse url link into following segments without using System.Uri

/Default.aspx/123/test?var1=val1

I need to break down this url link into values:

  1. File
  2. PathInfo
  3. Querystring

Answers


string pattern= "\b(?<protocol>https?|ftp|gopher|telnet|file|notes|ms-help)://(?<domain>[-A-Z0-9.]+)(?<file>/[-A-Z0-9+&@#/%=~_|!:,.;]*)?(?<parameters>\?[-A-Z0-9+&@#/%=~_|!:,.;]*)?"

This will generate named groups check for for what you want to extract


Here's one:

string pattern = @"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)"

Origin Link


Here is my code:

   var match = Regex.Match(internalUrl,
                            @"^\/([\w|\/|\-|\,|\s]+)\.([a-zA-Z]{2,5})([\w|\/|\-|\,|\s]*)\??(.*)",
                            RegexOptions.IgnoreCase | RegexOptions.Singleline |
                            RegexOptions.CultureInvariant | RegexOptions.Compiled);
    if (match.Success)
    {
        var filePath = match.Groups[1].Value;
        var fileExtention = match.Groups[2].Value;
        var pathInfo = match.Groups[3].Value;
        var queryString = match.Groups[4].Value;

        log.Debug("FilePath: " + filePath);
        log.Debug("FileExtention: " + fileExtention);
        log.Debug("PathInfo: " + pathInfo);
        log.Debug("QueryString: " + queryString);
    }

Need Your Help

How to remove particular functions from os library without editing the Lua headers or the scripts

lua

I have done my homework and studied other responses on this topic but none address my particular issue.

correct PHP headers for pdf file download

php pdf header

I'm really struggling to get my application to open a pdf when the user clicks on a link.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.