Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

URL Scrubber

Description
Cleans up long URLs.
Language
C#.net
Minimum Version
Created By
knoa
Contributors
-
Date Created
Aug 19, 2014
Date Last Modified
Dec 17, 2015

Macro Code

using System.Text.RegularExpressions;

public static class ClipboardFusionHelper
  {
    public static string ProcessText(string text)
      {
        text = Regex.Replace(text,
        @"(https?://www\.google\.[a-z.]+/search)(?(?=\?tbm=)(\?(tbm=[^&\s]*).*?(&q=[^&\s]*))|((?=.*?[?&](q=[^&\s]*))(?=.*?(&tbm=[^&\s]*))*))[a-zA-Z0-9-_./~*%$@:;,!?&=+#]*",
        "$1?$2$3$5$6");
        text = Regex.Replace(text,
        @"(https?://maps\.google\.[a-z.]+/maps)(?(?=\?q=)(\?(q=[^&\s]*)(?=.*?(&(?:s?ll|z|t)=[^&\s]*))*)|((?=.*?[?&](q=[^&\s]*))(?=.*?(&(?:s?ll|z|t)=[^&\s]*))*))[a-zA-Z0-9-_./~*%$@:;,!?&=+#]*",
        "$1?$2$3$5$6");
        text = Regex.Replace(text,
        @"(https?://www\.youtube\.com/watch).*?[?&](v=[^&\s]*)[a-zA-Z0-9-_./~*%$@:;,!?&=+#]*",
        "$1?$2");
        text = Regex.Replace(text,
        @"(https?://www\.amazon\.[a-z.]+).*?(/(dp|gp/product|exec/obidos/ASIN)/[A-Z0-9]+)[a-zA-Z0-9-_./~*%$@:;,!?&=+#]*",
        "$1$2/");
        return text;
      }
  }