Created
May 28, 2014 10:48
-
-
Save jordangray/8af3d596d242507d7b61 to your computer and use it in GitHub Desktop.
Very basic URL parsing with regular expressions and named capture groups.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Regex ParseUrl = new Regex(@"(?:^\w*:?//)? # Protocol | |
(?<domain> [\.\w]+) # Domain | |
(?::\d)? # Port | |
(?:/.*)? # Path", | |
RegexOptions.IgnoreCase | | |
RegexOptions.IgnorePatternWhitespace); | |
// Example usage | |
var domain = ParseUrl.Replace(url, @"${domain}"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment