Skip to content

Instantly share code, notes, and snippets.

@alexgman
Created April 7, 2017 17:51
Show Gist options
  • Save alexgman/05a7851411b412d0acbbc5fc552856d8 to your computer and use it in GitHub Desktop.
Save alexgman/05a7851411b412d0acbbc5fc552856d8 to your computer and use it in GitHub Desktop.
// Hyperlinks e.g. http://www.server.com/folder/file.aspx
Regex rxURL = new Regex(@"(\b(?:http|https|ftp|file)://[^\s]+)", RegexOptions.IgnoreCase);
rxURL.Match(strClipboardText);
foreach (Match rm in rxURL.Matches(strClipboardText))
{
if(!_hyperlink.Contains(rm.ToString()))
{
_hyperlink.Enqueue(rm.ToString());
FoundNewLinks = true;
}
}
// Files and folders - \\servername\foldername\
// TODO needs work
Regex rxFile = new Regex(@"(\b\w:\\[^ ]*)", RegexOptions.IgnoreCase);
rxFile.Match(strClipboardText);
foreach (Match rm in rxFile.Matches(strClipboardText))
{
if(!_hyperlink.Contains(rm.ToString()))
{
_hyperlink.Enqueue(rm.ToString());
FoundNewLinks = true;
}
}
// UNC Files
// TODO needs work
Regex rxUNC = new Regex(@"(\\\\[^\s/:\*\?\" + "\"" + @"\<\>\|]+)", RegexOptions.IgnoreCase);
rxUNC.Match(strClipboardText);
foreach (Match rm in rxUNC.Matches(strClipboardText))
{
if(!_hyperlink.Contains(rm.ToString()))
{
_hyperlink.Enqueue(rm.ToString());
FoundNewLinks = true;
}
}
// UNC folders
// TODO needs work
Regex rxUNCFolder = new Regex(@"(\\\\[^\s/:\*\?\" + "\"" + @"\<\>\|]+\\)", RegexOptions.IgnoreCase);
rxUNCFolder.Match(strClipboardText);
foreach (Match rm in rxUNCFolder.Matches(strClipboardText))
{
if(!_hyperlink.Contains(rm.ToString()))
{
_hyperlink.Enqueue(rm.ToString());
FoundNewLinks = true;
}
}
// Email Addresses
Regex rxEmailAddress = new Regex(@"([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)", RegexOptions.IgnoreCase);
rxEmailAddress.Match(strClipboardText);
foreach (Match rm in rxEmailAddress.Matches(strClipboardText))
{
if(!_hyperlink.Contains(rm.ToString()))
{
_hyperlink.Enqueue("mailto:" + rm.ToString());
FoundNewLinks = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment